WHITECOLOR
WHITECOLOR

Reputation: 26140

node.js: standard way to store app's configuration?

Is there standard ways of storing node.js app's configuration for different environments?

What I did to accomplish this:

created: node_app_folder/conf/general.js node_app_folder/conf/development.js node_app_folder/conf/production.js

general.js:

module.exports = {
    setting: "SOME GENERAL SETTING"
   ,setting2: ...
    ...
   // global conf has export method extend that just copies/replaces properties from supplied object
   extend: {...}

}

development.js and production.js contain setting specific for the environment.

in app.js:

global.conf = require('./conf/general');

// As I use express.js
app.configure('development', function(){       
   global.conf.extend(require('./conf/development'));
   ....
}
app.configure('production', function(){       
   global.conf.extend(require('./conf/producton'));
   ....
}

So then in my app's modules I can access app, configuration via global.conf object.

But I wonder if there are standard ways of doing the described task?

Thanks.

Upvotes: 5

Views: 3845

Answers (1)

alessioalex
alessioalex

Reputation: 63683

If you just want to get the values from JSON files then using Konphyg is perfect, here's a nice tutorial about it: http://nodetuts.com/tutorials/31-konphyg-cascading-configuration-files.html

There is no standard way of setting the configuration folder though, each does it in his own way.

Upvotes: 6

Related Questions