immutable-config
Simple immutable config library for node.js modules for servers, CLI utilities, and while using tools like gulp
.
Immutablity and merging of config objects is done by Seamless-Immutable.
Unflattening is done by Flat's unflatten
function.
Yargs is used to parse argv.
Explicitly define your ./config.js file:
var Config = require('immutable-config')
var defaults = {
}
Config.empty.merge([
defaults,
Config.env,
Config.unflattenedEnv,
Config.argvConfig || Config.envConfig || {},
Config.argv,
Config.unflattenedArgv
], {deep: true})
Or use the default merge (shown in the above example)
var config = require('immutable-config').config
ImmutableConfig.argvConfig
is the require
of the --config "some/filename.config.js"
from the commandline argv.
ImmutableConfig.unflattenedArgv
is the require
of the CONFIG=some/filename.config.js
environment variable.
Security:
ImmutableConfig
automatically uses the require
statement on the commandline argument --config
filename as well as environment veriable CONFIG
filename if they are present.