admin管理员组

文章数量:1315792

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.

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.

Share Improve this question edited Jul 18, 2014 at 7:17 raju asked Jul 3, 2014 at 12:35 rajuraju 5,00817 gold badges66 silver badges121 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

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);
};

本文标签: javascriptHow do I call a function at start in Expressjsnodejs (Setup method)Stack Overflow