1. string-env-interpolation
Use Environment Variables in String
string-env-interpolation
Package: string-env-interpolation
Created by: kamilkisiela
Last modified: Wed, 18 May 2022 20:43:14 GMT
Version: 1.0.1
License: MIT
Downloads: 11,596,487
Repository: https://github.com/kamilkisiela/string-env-interpolation

Install

npm install string-env-interpolation
yarn add string-env-interpolation

string-env-interpolation

Use string interpolation to provide Environment Variables.

Installation

yarn add string-env-interpolation
npm install string-env-interpolation

Usage

Let'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

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin