asynchronous函数导致模块初始化

假设这个简单的模块:

var mongoose = require('mongoose-util'); mongoose.myOwnCreateConnection(function(err, connection) { if(err) { console.log('log error somehow and make it die'); module.exports = null; } else { module.exports = connection; } }); 

它不会明显工作,但如何pipe理上下文模块初始化中的调用? 这里最好的做法是什么? 我只需要在模块init中使用函数声明吗? 提前致谢。 我问,因为快递有应用程序模块,一切都初始化。

要求是同步操作。 所以这是行不通的,你可以用这个:

asynchronousnodejs模块导出