An initializer function is used to ensure specific business logic is successfully executed on the same instance only once. This topic describes the structure and features of Node.js initializer functions.


The following code defines a simple initializer function.

exports.my_initializer = function(context, callback) {
    console.log('hello world');
    callback(null, "");

Function name

The my_initializer parameter must correspond to the initializer field that you specify when you add the initializer function. For example, if you set the initializer field to main.my_initializer when you create a function, after the initializer function is configured, Function Compute loads the my_initializer function you defined in the main.js file.


  • Input parameters of an initializer function contain context and callback parameters. These parameters are defined the same as those in event functions. For more information, see context parameter and callback function.
  • The initializer and initializationTimeout fields in the context parameter are specifically designed for initializer functions. If these two parameters are not specified, the initializer function is not executed.
  • Initializer functions do not return any value.