configuration-builder
Getting Started
npm i configuration-builder
import { DefaultConfigurationBuilder } from 'configuration-builder'
const configurationBuilder = new DefaultConfigurationBuilder();
const rootConfig = configurationBuilder
.setBasePath(basePath) // path to configs json fileds
.addJsonFiles() // load configs files
.addEnvironmentVariables() // parse environment variables and add to root config object
.addCommandLine() // parse command line variables and add to root config object
.addInMemoryCollection(config) // mix configuration from object
.setValidateSchema(validateSchema) // defined validation schema if needed
.build(); // merge all loaded configs
Usage:
Environment variables
Use prefix c__
if you want that config will put to application.
Allows set variables in next format:
c__param1__subParam=value1 c__param2=value2 c__defaultHost=localhost node index.js
Output config
Command line
Allows set variables in next format:
// double underline(__) separator
node index.js --param1__subParam value1 --param2 value2
// dot(.) separator
node index.js --param1.subParam value1 --param2 value2
// colon(:) separator
node index.js --param1:subParam value1 --param2 value2
Output config
File source config
Should set path to config dir
- Create folder ./config
- Add json files /**.config.json
a.config.json file
b.config.json file
- Set base config path
const builder = ;const config = builder;
Output config
Features
Ordering
- Json config loading.
- In memory collection.
- CommandLine arguments.
- Environment variables.
Templatization
Configuration templates using mustache https://www.npmjs.com/package/mustache
Output config structure
TODO List