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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With