read configuration form environment by specified format
install
npm i -S ding-env-config
// export CONFIG_mongo_db=db1
const envConfig = require('ding-env-config');
const config = envConfig();
// {
// "mongo": {
// "db": "db1"
// }
// }
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
// }
// }