Shamoon
Shamoon

Reputation: 43639

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

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

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

By the way, I'm using CoffeeScript

Upvotes: 1

Views: 952

Answers (1)

Chance
Chance

Reputation: 11323

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

Upvotes: 2

Related Questions