Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

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

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

Problem

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.

Problem courtesy of: WHITECOLOR

Solution

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.

Solution courtesy of: alessioalex

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

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

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×