Alexander Praetorius 1dff4fa2a3 ADD default .env file as a fallback
If a repository contains a `.env` example file or - in case of a private repository - a `.env` file with production values,
a developer can add a local (e.g. `.env.local` file to `.gitignore`) and feed it to `env-cmd`.
So in development a custom local configuration can be used, but in production, `env-cmd` falls back to `.env`
2017-02-21 09:51:36 +01:00
2017-02-21 09:51:36 +01:00
2016-08-16 20:00:47 -05:00
2016-08-16 20:00:47 -05:00
2016-12-06 21:52:00 -08:00

Travis Coveralls npm npm npm Standard - JavaScript Style Guide

env-cmd

A simple node program for executing commands using an environment from an env file.

Install

npm install env-cmd or npm install -g env-cmd

Usage

Environment File Usage

Environment file ./test/.env

# This is a comment
ENV1=THANKS # Yay inline comments support
ENV2=FOR ALL
ENV3 THE FISH # This format is also accepted

# Surround value in double quotes when using a # symbol in the value
ENV4="ValueContains#Symbol"

# If using double quotes as part of the value, you must surround the value in double quotes
ENV5=""Value includes double quotes""

Package.json

{
  "scripts": {
    "test": "env-cmd ./test/.env mocha -R spec"
  }
}

or

Terminal

./node_modules/.bin/env-cmd ./test/.env node index.js

.rc file usage

.rc file .env-cmdrc

{
  "development": {
    "ENV1": "Thanks",
    "ENV2": "For All"
  },
  "production": {
    "ENV1": "The Fish"
  }
}

Terminal

./node_modules/.bin/env-cmd production node index.js

Environment File Formats

These are the currently accepted environment file formats. If any other formats are desired please create an issue.

  • key=value
  • key value
  • Key/value pairs as JSON
  • JavaScript file exporting an object
  • .env-cmdrc file (as valid json) in execution directory

Why

Because sometimes its just too cumbersome passing lots of environment variables to scripts. Its usually just easier to have a file with all the vars in them, especially for development and testing.

Do not commit sensitive environment data to a public git repo!

cross-env - Cross platform setting of environment scripts

Special Thanks

Special thanks to cross-env for inspiration (use's the same cross-spawn lib underneath too).

Contributors

  • Eric Lanehart
  • Jon Scheiding

Contributing Guide

I welcome all pull requests. Please make sure you add appropriate test cases for any features added. Before opening a PR please make sure to run the following scripts:

  • npm run lint checks for code errors and formats according to js-standard
  • npm test make sure all tests pass
  • npm run test-cover make sure the coverage has not decreased from current master
Description
Setting environment variables from a file
Readme MIT 1.2 MiB
Languages
TypeScript 98%
JavaScript 2%