default-env

1.0.0 • Public • Published

defaultEnv

Composable cascading environment variable defaults.

NPM version Build Status MIT License

The environments your app runs in don't divide into neat buckets like development, staging, and production. Your client side unit tests shouldn't spend time minifying. Your integration tests should. You always minify in production. Your continuous integration host doesn't install the browser that gives you nice test failure debugging in development, but sometimes you want to run those just like CI, because they fail there but pass on your machine.

Instead of coding all those configuration rules into your app, layer on additive environments. Define your environments near eachother, so the composition is easy to reason about.

Variables explicitly set in the environment always have final say.

Usage

npm install default-env
var defaultEnv = require('default-env')
 
defaultEnv.define({
  test: {
    PORT: 4001,
    LOG_LEVEL: 'error',
    OPTIMIZE: false
  },
  integration: {
    OPTIMIZE: true
  },
  development: {
    OPTIMIZE: false,
    PORT: 4000,
    LOG_LEVEL: 'warning'
  },
  production: {
    OPTIMIZE: true,
    LOG_LEVEL: 'verbose'
  }
})
 
task('test:integation', function() {
  defaultEnv.use('test', 'integration')
  // ...
})
 

See tests for more examples.

Contributing

Please follow our Code of Conduct when contributing to this project.

$ git clone https://github.com/goodeggs/default-env && cd default-env
$ npm install
$ npm test

Module scaffold generated by generator-goodeggs-npm.

Package Sidebar

Install

npm i default-env

Weekly Downloads

7

Version

1.0.0

License

MIT

Last publish

Collaborators

  • hurrymaplelad