Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 771
raju Avatar asked Jul 03 '14 12:07

raju


1 Answers

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);
like image 108
Benjamin Gruenbaum Avatar answered Sep 28 '22 04:09

Benjamin Gruenbaum