我如何在Node.js中指定不同的configuration文件?

try config = JSON.parse(fs.readFileSync('./config.json', 'ascii')) catch e util.debug("Could not parse configuration file.\n" + e.stack) return 

我有我的node.js代码,我有两个configuration文件“

  • config.json.prod
  • config.json.local

我怎样才能指定它应该运行.local

顺便说一下,我正在使用CoffeeScript

是的,你当然可以。 Checkout nodepad(伟大的参考应用程序):

https://github.com/alexyoung/nodepad/blob/master/app.js

来源来自这个博客系列: http : //dailyjs.com/2010/11/01/node-tutorial/

编辑 :例如

 if (app.settings.env == 'production') { mailer.send(mailOptions, function(err, result) { if (err) { console.log(err); } } ); } 

他使用app.settings.env来换出不同的环境/应用程序设置。 同样可以用来加载configuration文件。 – 机会