envterpolate
v1.1.0
Published
Tiny Dotenv Environment Variable Interpolator
Downloads
2
Readme
envterpolate
Tiny Dotenv Environment Variable Interpolator
This package implements a simple idea: interpolate strings taken from your npm package users, using variables they defined in their dotenv files. This is useful for those "last mile" customization that can't be committed to the repository (database parameters, passwords, etc)
Given two things:
- File:
.env
, written in dotenv syntax, containing a really important password, NOT committed to repo and added to.gitignore
:
MY_SECRET_PASSWORD=(|-|U(|< |\|0rr15
- File:
package.json
, with strings containing variables defined in.env
:
packageJson = {
// ...
"yourPluginConfig": {
cliArgs: "--save --password ${MY_SECRET_PASSWORD}"
}
// ...
}
... Then you can use envterpolate
to read the file with the dotenv environment variables expanded:
import {interpolateJson} from 'envterpolate';
const packageJson = interpolateJson('package.json', '.env')
console.log(packageJson)
/**
{
// ...
"yourPluginConfig": {
cliArgs: "--save --password (|-|U(|< |\|0rr15"
}
// ...
}
**/