Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 364
WHITECOLOR Avatar asked Dec 23 '11 10:12

WHITECOLOR


1 Answers

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.

like image 93
alessioalex Avatar answered Sep 20 '22 15:09

alessioalex