nconf icon indicating copy to clipboard operation
nconf copied to clipboard

How to save all config (defaults included) to file?

Open todbot opened this issue 9 years ago • 2 comments

How do I set up nconf so the saved config file contains both set() and defaults values? For instance:

nconf.file({file: "config.json"});
nconf.defaults({example1: "value"});
nconf.set('example2', "another value");
nconf.save();  // config.json contains only "example2", but I also want "example1"

todbot avatar Apr 19 '16 01:04 todbot

@todbot we should have an export function on the nconf instance that gives the full JSON state from all stores merged with proper priority.

jcrugzz avatar Apr 19 '16 19:04 jcrugzz

Thanks for the update.

For anyone who cares, here's how I've been solving what I needed to do:

var conf_defaults = require('./config-defaults.json');
var conf_file = './config.json';
if( ! fs.existsSync(conf_file) ) {
    fs.writeFileSync( conf_file, JSON.stringify(conf_defaults,null, 2) );
}
nconf.file({file: conf_file});

Basically, copy over a starter config file for the real one, and then tell nconf to use it.

todbot avatar Apr 20 '16 03:04 todbot