This package has been deprecated

Author message:

remove

configuration-builder
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

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

{
  "param1": {
    "subParam":"value1"   
   },
  "param2": "value2",
 
}

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

{
  "param1": {
    "subParam":"value1"   
   },
  "param2": "value2"
 
}

File source config

Should set path to config dir

  1. Create folder ./config
  2. Add json files /**.config.json

a.config.json file

{
  "param1": {
    "subParam":"value1"   
   },
  "param2": "value2"
 
}

b.config.json file

{
  "param3": {
    "subParam":"value1"   
   },
  "param4": "value2"
 
}
  1. Set base config path
const builder = new DefaultConfigurationBuilder();
const config = builder.setBasePath('./config').addJsonFiles().build();
 

Output config

{
  "param1": {
    "subParam":"value1"   
   },
  "param2": "value2",
  "param3": {
    "subParam":"value1"   
   },
  "param4": "value2"
}

Features

Ordering

  1. Json config loading.
  2. In memory collection.
  3. CommandLine arguments.
  4. Environment variables.

Templatization

Configuration templates using mustache https://www.npmjs.com/package/mustache

{
   "hostName": "google.com",
   "secureHostName": "https://{{hostName}}"
}

Output config structure

{
   "hostName": "google.com",
   "secureHostName": "https://google.com"
}

TODO List

Readme

Keywords

Package Sidebar

Install

npm i configuration-builder

Weekly Downloads

0

Version

1.0.3

License

ISC

Unpacked Size

29 kB

Total Files

40

Last publish

Collaborators

  • npm