How do I call a function at start in Expressjs/nodejs (Setup method)
express, javascript, node.js
Solution
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);
Problem
I want my worker server to pickup tasks from parent server immediately after it starts and keep pinging for pending tasks. Given that Nodejs is a event driven, how do I make my express server make a rest call to server and start working immediately after start? In a way, I am asking for setup method in Nodejs.