Super simple config loader.
confiig
loads configuration based on NODE_ENV
environment variable.
$ npm install confiig
Basically, configuration loads from ./config
directory.
You can set CONFIG_PATH
environment variable to change default config path.
confiig
tries to load config file that named like BUILD_PHASE or NODE_ENV
+ '.js'.
βββ config
βΒ Β βββ cbt.js
βΒ Β βββ default.js
βΒ Β βββ development.js
βΒ Β βββ local.js
βΒ Β βββ production.js
βΒ Β βββ sandbox.js
const conf = require('confiig');
console.log(conf.read('foo.bar'));
If 'default.js' config file exists in config path then configuration consisted based on the 'default' file and merged NODE_ENV
configs into default one.
Multiple configs can be merged with separator.
For example, set NODE_ENV
with separator /
like local/foo
then default.js + local.js + foo.js
configs are merged.
If the NODE_ENV
or BUILD_PHASE
environment variable changes, it will automatically reread and merge the config files and return the path values when you call the read method. If no changes that environment variable, then it memoization that merged configs.
const conf = require('confiig');
process.env.NODE_ENV = 'development';
console.log(conf.read('foo.bar')); // development config value
process.env.NODE_ENV = 'sandbox';
console.log(conf.read('foo.bar')); // sandbox config value
.read(path, [defaultValue])
path (string)
: The path of the property to get.
defaultValue (any)
: The value returned for undefined resolved values. Optional.
returns (any)
: the value in the config if found, otherwise it returns undefined.
May be freely distributed under the MIT license.
Copyright (c) 2021-2023 eu81273