You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I run database='{"host": "helloworld.com"}' node index.js The database property will return both the port property and the host property. I'd expect my environment variable to completely ovveride and only give me the host property. This is what I get back instead:
{
port: 3000,
host: "helloworld.com"
}
The text was updated successfully, but these errors were encountered:
nconf considers all hierarchical keys' uniqueness, and thus also the final value of a key's value returned by get(), based on the full chain of keys in the hierarchy. It does not, generally, override a key that is itself an object in its entirety.
In your example, nconf starts by parsing your env arg, and gets a single 'key': database:host
It then adds a file store, which contains another 'key': database:port
This is how it maintains the hierarchy so you can call nconf.get('database:port') instead of having to call nconf.get('database') and then pulling the port value out.
nconf is doing what it is supposed to here; in order for you to override the database:port value on the command line, you'd need to set it explicitly in the database value to the correct value in context of your code. Essentially, nconf considers that 'unset' in the parsed env store, so it returns the value from your file store.
This is how it is supposed to work, so you may need to change the interpretation of these values in your code, or how your config is structured, if you'd like to override the behavior in order to remove port from your database settings if env does not contain it.
Is there a way to force the deletion of a part of the config ? I'm running into the same issue in our unit tests, and I would like to override completely some nested values that come from the config file.
Even setting it to undefined or a random string before giving it the intended object value does not do the trick. Any workaround would be nice.
Hi,
Thanks for your work on this project. Just say I have the following files`
config.json:
index.js
When I run
database='{"host": "helloworld.com"}' node index.js
The database property will return both the port property and the host property. I'd expect my environment variable to completely ovveride and only give me thehost
property. This is what I get back instead:The text was updated successfully, but these errors were encountered: