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 badges2 Answers
Reset to default 6You 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
版权声明:本文标题:javascript - How do I call a function at start in Expressjsnodejs (Setup method) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741990927a2409089.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论