nconf
nconf copied to clipboard
Store save order seems to be reverse of merge order
When keys are modified and saved. They get saved to the first file to be opened not the last in the merge list. This seems to break any ability to have a second file load and not have it always override a saved key/value pair. At very least the save order and read order needs to be documented.
I have a similar problem. My application can be extended using plugins, these plugins all have their own configuration file. Reading the separate configuration files is fine, but when I make an update in one module these updates are written to the configuration file first opened. It seems updates are made in the wrong nconf object.
I solved my issue using new nconf.Provider().
I have the same problem.
I solved my issue using new nconf.Provider()
How ?
All changes i made are saved in one file, as example:
var nconf = require("nconf");
nconf = new nconf.Provider();
// config files
nconf.file("webserver", "./conf/webserver.json");
nconf.file("database", "./conf/database.json");
nconf.file("plugins", "./conf/plugins.json");
nconf.file("logging", "./conf/logging.json");
nconf.set("logging:levels", {
"error": "1",
"warn": "2",
"debug": "3"
});
nconf.set("database:port", 85888);
nconf.save(function(err){
console.log(err);
});
console.log(nconf);
console.log( nconf.get("database:port") );
all changes are written in "webserver.json"
I'm having the same issue...
+1
+1 to bug that @karrots reported. Still an issue in 2022.
As @reneklootwijk suggested above I was able to replace the usual var nconf = require('nconf')
with var nconf = new (require('nconf')).Provider()
in the master app and all plugins/modules and that solves the issue. Now each module is responsible for calling nconf.save()
to save its respective settings to its own json settings file.
PRs with appropriate tests are always welcome. :-)
v1 is a server major release, so breaking current assumptions or design from v0.x is acceptable.
I agree that the order of operations is confusing.