Colons separate nconf hierarchies, e.g.,
{
"AUTH": {
"ENABLED": true
}
}
is accessed via:
nconf.get("AUTH:ENABLED");
I'd like to override this via environment and/or command line options under npm start
, e.g.,
AUTH:ENABLED=false npm start
This fails under both bash and zsh because of the colon. Escaping the colon with \
doesn't help.
The following also fails under all circumstances (hierarchical or not):
npm start --AUTH:ENABLED=false
How can I pass a hierarchical config value through to nconf/optimist in a way that works?
Easiest thing is to configure nconf to use a less-terrible separator character as per the docs:
//
// Or use both options
//
nconf.env({
separator: '__',
whitelist: ['database__host', 'only', 'load', 'these', 'values']
});
var dbHost = nconf.get('database:host');
My other suggestion is consider a less-bizarre configuration module. There are dozens on npm. Looking through the nconf github issues I see enough warning signs that this module is just doing too much with too many options. Configuration should be straightforward. If it isn't, walk away. My guess is while this might be appropriate if you are building a PaaS such as nodejitsu, most applications don't need an infinitely deep config hierarchy with a dozen different places to check for data.
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