cz
A simple config utility for nodejs
Example
const path = require('path');
const config = require('cz');
config.load('./config.json');
config.set('random', 'random value');
console.log('config', config.get());
console.log('db:host', config.get('db:host'));
console.log('mongodb://' + config.get('db:username') + ':' + config.get('db:password') + '@' + config.get('db:host') + ':' + config.get('db:port') + '/' + config.get('db:collection'));
console.log('mongodb://' + config.joinGets(['db:username', 'db:password', 'db:host', 'db:port', 'db:collection'], [':', '@', ':', '/']));
Hierarchical configuration
Cz sets defaults()
as the most bottom object and applies all changes to the config object on top of that meaning anywhere in your app you can use config.defaults({})
to override the default values.
const config = require('cz');
config.defaults({
port: 4000,
logging: false
});
config.set('port', 5000);
config.get('port');
config.reset();
config.get('port');
To reset defaults just use config.defaults({});
To reset the config itself we provide config.reset();