envterpolate
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i envterpolate

Weekly Downloads

1

Version

1.1.0

License

MIT

Last publish

Collaborators

  • codekiln