Skip to content

Super simple config library for node.js application 🚚

License

Notifications You must be signed in to change notification settings

eu81273/confiig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

confiig

Super simple config loader. confiig loads configuration based on NODE_ENV environment variable.


Getting Started

$ npm install confiig

Usage

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'));

Default config

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

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.

Dynamic NODE_ENV

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



API

.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.

License

May be freely distributed under the MIT license.

Copyright (c) 2021-2023 eu81273

About

Super simple config library for node.js application 🚚

Resources

License

Stars

Watchers

Forks

Packages

No packages published