开发者

How can I specify different config files in Node.js?

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

I have that in my node.js code and I have two config files"

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

How can I specify that it should run the .local?

By the way, I'm using CoffeeScript


Yea, you certainly can. Checkout nodepad (great reference app):

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

The source comes from this blog series: http://dailyjs.com/2010/11/01/node-tutorial/

Edit: For example

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

he uses app.settings.env to swap out different environmental/app settings. Same could be used to load a config file. – Chance

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜