在服务器开始监听之前调用异步函数
Calling async function befrore server start to listen
我有节点应用程序,我想在服务器启动之前调用函数,我的问题是:
- 推荐的原因是什么?
- 这会不会有问题(我在服务器启动之前调用了一些异步函数)
顺便说一句,我用的是蓝鸟
这是我的代码
//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);
});
.....
我没有 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'));
}
});
});
我有节点应用程序,我想在服务器启动之前调用函数,我的问题是:
- 推荐的原因是什么?
- 这会不会有问题(我在服务器启动之前调用了一些异步函数)
顺便说一句,我用的是蓝鸟
这是我的代码
//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);
});
.....
我没有 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'));
}
});
});