Skip to content

read configuration form environment by specified format

License

Notifications You must be signed in to change notification settings

yidinghan/ding-env-config

Repository files navigation

env-config

Greenkeeper badge

Travis Coveralls npm npm npm

read configuration form environment by specified format

Getting Start

NPM

install

npm i -S ding-env-config

Usage

// export CONFIG_mongo_db=db1
const envConfig = require('ding-env-config');
const config = envConfig();
// {
//   "mongo": {
//     "db": "db1"
//   }
// }

envConfig([payload]) ⇒ object

once there are somethings like CONFIG_mongo_db in env, the codes below will set config.mongo.db to the env val

Kind: global function Returns: object - parse out config

Param Type Default Description
[payload] object input arguments
[payload.config] object {} default config object
[payload.separator] string "_" symbol between key path and prefix
[payload.prefix] string "CONFIG" prefix to match target environment

Example

// export CONFIG_mongo_db=db1
const config = envConfig();
// {
//   "mongo": {
//     "db": "db1"
//   }
// }

// export CONFIG_mongo_port__num=27017
const config = envConfig();
// {
//   "mongo": {
//     "port": 27017
//   }
// }

// export CONFIG_mongo_flag=true
const config = envConfig();
// {
//   "mongo": {
//     "flag": "true"
//   }
// }

// export CONFIG_mongo_flag__bool=true
const config = envConfig();
// {
//   "mongo": {
//     "flag": true
//   }
// }

About

read configuration form environment by specified format

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published