1.1.0 • Published 7 years ago

envterpolate v1.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

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"
  }
  // ...
}
**/