read config also from environment variables, merge on top of json file config

This commit is contained in:
Riku Rouvila
2015-11-24 20:21:31 +02:00
parent 35fc0b9ea8
commit a20b1f6cd2
5 changed files with 20 additions and 25 deletions

View File

@@ -4,4 +4,18 @@ var _ = require('lodash');
var config = require('../config.json');
var env = process.env.NODE_ENV || 'development';
module.exports = _.merge({}, config.all, config[env]);
// TWITTER_CONSUMER_KEY => twitter.consumerKey
function toPath(key) {
var parts = key.split('_');
var namespace = parts[0].toLowerCase();
var option = _.camelCase(_.tail(parts).join('_'))
return option ? [namespace, option].join('.') : namespace;
}
var envVars = _.reduce(process.env, function(memo, value, key) {
return _.set(memo, toPath(key), value);
}, {});
module.exports = _.merge({}, config.all, config[env], envVars);