nconf icon indicating copy to clipboard operation
nconf copied to clipboard

Provide the way to override attributes of settings

Open zalun opened this issue 12 years ago • 4 comments

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.

zalun avatar Jun 01 '12 12:06 zalun

+1 for the question... facing the same...

domguinard avatar Aug 13 '12 13:08 domguinard

does .merge({'settingA', {'attributeA': 'localValueA'}) do as you want?

bmeck avatar Sep 07 '12 19:09 bmeck

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.

indexzero avatar Dec 23 '12 21:12 indexzero

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 👍

mansona avatar Feb 26 '17 08:02 mansona