nconf
nconf copied to clipboard
How to save all config (defaults included) to file?
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 we should have an export function on the nconf instance that gives the full JSON state from all stores merged with proper priority.
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.