package
Use Environment Variables in String
npm install string-env-interpolationGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Estimated unpacked size across 1 packages.
3.9 kB
Includes dependencies.
Use string interpolation to provide Environment Variables.
yarn add string-env-interpolation
npm install string-env-interpolationLet's say we have a config file: config.yaml.
debug: ${DEBUG:false}
name: ${NAME:"Development"}
user: ${USER}Our library wants to be able to consume environment variables in index.js.
import { env } from "string-env-interpolation";
import { readFileSync } from "fs";
const content = env(readFileSync("./config.yaml", "utf-8"));
console.log(content);Outputs:
DEBUG=true USER=kamil node index.js
# Output
debug: true
name: Development
user: kamil
NAME=Production USER=kamil node index.js
# Output
debug: false
name: Production
user: kamil