nconf icon indicating copy to clipboard operation
nconf copied to clipboard

Store save order seems to be reverse of merge order

Open karrots opened this issue 9 years ago • 7 comments

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.

karrots avatar Jan 20 '16 05:01 karrots

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.

reneklootwijk avatar Feb 13 '16 08:02 reneklootwijk

I solved my issue using new nconf.Provider().

reneklootwijk avatar Feb 13 '16 09:02 reneklootwijk

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"

mStirner avatar Feb 27 '16 12:02 mStirner

I'm having the same issue...

evertiro avatar Feb 29 '16 10:02 evertiro

+1

markjbyrne81 avatar Dec 05 '16 16:12 markjbyrne81

+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.

LowPowerLab avatar Jan 11 '22 15:01 LowPowerLab

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.

mhamann avatar Jan 12 '22 01:01 mhamann