nconf
nconf copied to clipboard
Provide the way to override attributes of settings
I'm trying to provide several configuration files which are overriding each other
config-default.json
's settings are overriden by config-{DEV_ENV}.json
and these by config-local.json
I'm using this:
conf.add('local-file', {'type': 'file', file: path.join(__dirname, './config-local.json')});
var current_env = process.env['DEV_ENV'] || 'development';
conf.add('env-file', {'type': 'file', file: path.join(__dirname, './config-' + current_env + '.json')});
conf.add('default-file', {'type': 'file', file: path.join(__dirname, './config-default.json')});
It's working well, however I'm unable to override parts of the object:
if config-default.json
has a setting settingA
defined in such way:
{
"settingA": {
"attributeA": "valueA",
"attributeB": "valueB"
}
}
it can be accessed by conf.get('settingA:attributeA')
. I wish to override just this value in any other file. This is not working for obvious reasons (overrides entire setting):
{
"settingA": {
"attributeA": "localValueA"
}
}
But there is a syntax which isn't used and could work well:
{
"settingA:attributeA": "localValueA"
}
Please tell me it's sane and if I'm using your lib in the right way.
+1 for the question... facing the same...
does .merge({'settingA', {'attributeA': 'localValueA'}) do as you want?
This is by design. There is no way exposed to force the hierarchy to not merge objects from various providers. To work around this in the config you wish to use to override entirely put:
{
"settingA": {
"attributeA": "valueA",
"attributeB": null
}
}
If you could provide a failing test for this that would be really helpful.
Does this test cover the use case: https://github.com/indexzero/nconf/pull/255
It's not failing but I came across something very similar and thought it was a bug but turned out it was an issue on my end. Me writing that test was a way for me to confirm it was my issue 👍