很久以后,我发现了一个非常好的 node .用于管理配置的js模块:nconf.
一个简单的例子:
var nconf = require('nconf');
// First consider commandline arguments and environment variables, respectively.
nconf.argv().env();
// Then load configuration from a designated file.
nconf.file({ file: 'config.json' });
// Provide default values for settings not provided above.
nconf.defaults({
'http': {
'port': 1337
}
});
// Once this is in place, you can just use nconf.get to get your settings.
// So this would configure `myApp` to listen on port 1337 if the port
// has not been overridden by any of the three configuration inputs
// mentioned above.
myApp.listen(nconf.get('http:port'));
它还支持将设置存储在Redis中,编写配置文件,并且有一个相当可靠的API,还得到了一个更受尊敬的 node 的支持.js shops,Nodejitsu,作为Flatiron框架计划的一部分,所以它应该是future 的证明.
看看nconf at Github.