Skip to main content

Functions

The ./src/index.js file (or ./src/index.ts file in a TypeScript-based project) includes global register, bootstrap and destroy functions that can be used to add dynamic and logic-based configurations.

The functions can be synchronous, asynchronous, or return a promise.

Synchronous function

module.exports = {
register() {
// some sync code
},
bootstrap() {
// some sync code
},
destroy() {
// some sync code
}
};

Asynchronous function

module.exports = {
async register() {
// some async code
},
async bootstrap() {
// some async code
},
async destroy() {
// some async code
}
};

Function returning a promise

module.exports = {
register() {
return new Promise(/* some code */);
},
bootstrap() {
return new Promise(/* some code */);
},
destroy() {
return new Promise(/* some code */);
}
};

Register

The register lifecycle function, found in ./src/index.js (or in ./src/index.ts), is an asynchronous function that runs before the application is initialized. It can be used to:

register() is the very first thing that happens when a Strapi application is starting. This happens before any setup process and you don't have any access to database, routes, policies, or any other backend server elements within the register() function.

Bootstrap

The bootstrap lifecycle function, found in ./src/index.js (or in ./src/index.ts), is called at every server start.

It can be used to:

The bootstrapi() function is run before the back-end server starts but after the Strapi application has setup, so you have access to anything from the strapi object.

💡 Tip

You can run yarn strapi console (or npm run strapi console) in the terminal and interact with the strapi object.

Destroy

The destroy function, found in ./src/index.js (or in ./src/index.ts), is an asynchronous function that runs before the application gets shut down.

It can be used to gracefully: