How do I call a function at start in Expressjs/nodejs (Setup method) How do I call a function at start in Expressjs/nodejs (Setup method) express express

How do I call a function at start in Expressjs/nodejs (Setup method)


You have your server.js file (the one you call node server.js on).

Simply place whatever code you need to run at bootstrap there.

var express = require("express");...yourSetupFunction();app.listen(1337);


I'm not sure what type of tasks you fetch from parent node. So I'm assuming you just want to know when the new server is ready to use and perform actions based on that.

The express documentation mentions about app.listen as a function that can be configured.

Here's the code block

app.listen = function(){    var server = http.createServer(this);    //yourBootstrap();    return server.listen.apply(server, arguments);};