我是节点应用程序,我想在服务器启动之前调用函数,我的问题是:
顺便说一句,我使用蓝鸟
这是我的代码
//This is the function which I want to call before
process.beforeProc();
//Before I start the following server
http.createServer(app).listen(app.get('port'), function (err) {
if (err) {
console.error(err);
} else {
console.log('listening on port ' + app.get('port'));
}
});
**UPDATE**
The preProcess look like following
exports.beforeProc= function () {
run.validate(function (err) {
console.log(err);
process.exit(1);
});
Parser.parse().then(function (con) {
//Cache the path values to serve new requests
if (typeof require.cache.persist === 'undefined') {
require.cache.persist = {};
}
require.cache.persist.con = con;
}, function (err) {
console.log(err);
});
.....
答案 0 :(得分:2)
我没有50个代表所以我回答了问题:
process.beforeProc()是否有回调? 如果是这样,你可以这样做:
process.beforeProc(function() {
// Once the beforeProc loaded it will return the callback, so whats
// in here
http.createServer(app).listen(app.get('port'), function (err) {
if (err) {
console.error(err);
} else {
console.log('listening on port ' + app.get('port'));
}
});
});