我很担心应用程序启动在Express中的工作方式。我将解释我的用例:了解ExpressJS应用程序启动
我有一个配置管理器模块,供所有其他应用程序模块使用来加载所需的配置。我设置配置app.listen
:
app.listen(9000, function() {
try
{
config_manager.setSiteConfig();
console.log('settings..!!!')
}
catch(err)
{
console.log(err.stack);
}
});
在同一个应用程序我所说的配置管理器功能加载配置的另一个模块,但它返回空。代码是这样的:
var config_manager = require('configuration-manager');
console.log(config_manager.loadConfig()); // returns empty object {}
我使用node app.js
运行应用程序。首先打印空物体,然后('settings..!!!')
。在致电app.listen()
之前,Express是否编译脚本?如何在编译/加载其他文件之前确保我的配置已设置?
配置被加载到单独的文件(其他然后app.js)。我将配置文件设置为在app.listen中加载 –