codekiln / envterpolate

Tiny Interpolator For Dotenv Environment Variables

Home Page:https://codekiln.github.io/envterpolate/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

envterpolate

Tiny Dotenv Environment Variable Interpolator

styled with prettier Greenkeeper badge Travis Coverage Status

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:

  1. File: .env, written in dotenv syntax, containing a really important password, NOT committed to repo and added to .gitignore:
MY_SECRET_PASSWORD=(|-|U(|< |\|0rr15
  1. 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"
  }
  // ...
}
**/

About

Tiny Interpolator For Dotenv Environment Variables

https://codekiln.github.io/envterpolate/

License:MIT License


Languages

Language:TypeScript 89.3%Language:JavaScript 10.7%