env-inject-params
v1.0.5
Published
Add Environment parameter values into object.
Downloads
6
Maintainers
Readme
env-inject-params
Module allows to replace placeholders of object/structure with values from System Environment.
This module is commonly used with Config generation that will make you application deployment simpler as well as independent from deployment environment.
Install
npm install env-inject-params --save
Usage
import envInjectParams from 'env-inject-params';
Putting Parameter Store data into data structure
Export value into environment e.g. bash:
export SERVICE_NAME='MySuperApp'
Prepare object with placeholder (environment variable name wrapped with ${} ):
const data = {
path: '/application/${SERVICE_NAME}',
enabled: true,
}
Using the module:
const dataWithValue = envInjectParams.getValuesFromEnv(data);
console.log(dataWithValue);
should print you data structure as below:
{
path: '/application/MySuperApp',
enabled: true
}
If given placeholder is not defined in environment exception is thrown:
const data = {
path: '/application/${NO_SUCH_THING}',
enabled: true,
}
Error thrown:
Error: 'ENV Placeholder 'NO_SUCH_THING' undefined !'