I wrote the cli-config API to manage NodeJS app configuration including:
- Package defaults
- Local user config
- Command line options
- App overrides
Visit https://github.com/tohagan/cli-config for more details.
Example 1:
Combines configuration options from package file defaults.config then ~/.<appname>.config then command line options then force the debug option to be true. Uses a shallow merge so only the top level properties are merged.
var config = require('../cli-config')
.getConfig({dirname: __dirname, override: {debug: true}});
Example 2:
Deep merge nested configuration settings from package defaults.config then ./config.json then command line options. If ./config.json does not exist, clone a copy from defaults.config so the user can use it to override defaults.config in the future.
var config = require('../cli-config').getConfig({
dirname: __dirname,
clone: true,
configFile: './config.json',
merge: 'deep'
});
Example 3:
The command line parser returns an object that can be used to override the system settings or user settings options. You can configure this parser using the cli option. Refer to minimist for more details about command line parsing options.
var config = require('../cli-config').getConfig({
dirname: __dirname,
cli: {
boolean: {
'd': 'debug',
'v': 'verbose'
}
}
});
Sets the config.debug and config.verbose options to true.
$ myapp -d -v