后来,我找到了一个很好的用于管理配置的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,并且作为Flatiron框架计划的一部分,还得到了备受推崇的Node.js商店之一Nodejitsu的支持。相当适合未来。
在Github上查看nconf。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)