docs

Boot Operations

Boot operations allow you to execute custom logic before the server initialization. Unlike middlewares, boot operations are not tied to handling specific requests but are used to perform tasks like setting up configurations, initializing services, or running pre-start logic. To define a boot operation, add it to app/middlewares/boot.ts.

Structure of a Boot Operation

Each boot operation is an object that contains:

All boot operations listed in bootOperations are executed sequentially.

1. Boot Operation Without Parameters

A simple boot operation that doesn’t require parameters:

export const bootOperations: OperationsType[] = [
  {
    function: () => {
      console.log("Server initialization started.");
    },
    params: [], // No parameters needed
  },
];

2. Boot Operation With Parameters

You can pass parameters to the function using the params array:

export const bootOperations: OperationsType[] = [
  {
    function: (name, environment) => {
      console.log(`Initializing ${name} in ${environment} mode.`);
    },
    params: ["Server", "Production"],
  },
];

3. Executing Multiple Boot Operations

You can define multiple boot operations to be executed in sequence:

export const bootOperations: OperationsType[] = [
  {
    function: () => {
      console.log("Connecting to the database...");
    },
    params: [],
  },
  {
    function: (service) => {
      console.log(`Initializing service: ${service}`);
    },
    params: ["AuthService"],
  },
  {
    function: (message) => {
      console.log(message);
    },
    params: ["Server is ready to start!"],
  },
];

Summary