node-config-refactor
config-refactor
helps you to refactor your configurations which you load by node-config.
This tool generates config files from your actual configurations.
For example, from following configurations,
# NODE_CONFIG_ENV=development NODE_APP_INSTANCE=foo "a": "default" "b": "development" "c": "foo" "d": "development-foo"# NODE_CONFIG_ENV=development NODE_APP_INSTANCE=bar "a": "default" "b": "development" "c": "bar" "d": "development-bar"# NODE_CONFIG_ENV=production NODE_APP_INSTANCE=foo "a": "default" "b": "production" "c": "foo" "d": "production-foo"# NODE_CONFIG_ENV=production NODE_APP_INSTANCE=bar "a": "default" "b": "production" "c": "bar" "d": "production-bar"
Generates following files.
# defaultjson a: "default" # default-foojson c: 'foo' # default-barjson c: 'bar' # developmentjson b: 'development' # development-foojson d: 'development-foo' # development-barjson d: 'development-bar' # productionjson b: 'production' # production-foojson d: 'production-foo' # production-barjson d: 'production-bar'
Usage
If your environments are like followings,
NODE_CONFIG_ENV=development NODE_APP_INSTANCE=foo
NODE_CONFIG_ENV=development NODE_APP_INSTANCE=bar
NODE_CONFIG_ENV=production NODE_APP_INSTANCE=foo
NODE_CONFIG_ENV=production NODE_APP_INSTANCE=bar
Execute the following command.
$ NODE_CONFIG_DIR=... npx config-refactor \ -c development:foo \ -c development:bar \ -c production:foo \ -c production:bar
By default, config-refactor
outputs generated JSON to the stdout.
To output config files, use -o/--out
option.
$ NODE_CONFIG_DIR=... npx config-refactor \ ... \ -o path/to/configDir
Atomic config object
Sometimes we want to treat data object as a set.
# config A "obj": "a": "A" "x": "common" # config B "obj": "b": "B" "x": "common"
if keys are specified by -a/--atomic
option, the value is treated as atomic.
$ config-refactor ...# outputs following
Note
This tool currently supports deployment
and instance
. See https://github.com/lorenwest/node-config/wiki/Configuration-Files#file-load-order about deployment
and instance
.
default.EXT
default-{instance}.EXT
{deployment}.EXT
{deployment}-{instance}.EXT
EXT
of the input file can be the formats node-config
supports.
But this tool outputs only json format.