@tiaanduplessis/env

Get access to your environment configuration

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
11Jun 2, 2019Oct 31, 2017Minified + gzip package size for @tiaanduplessis/env in KB

Readme

@tiaanduplessis/env

package version package downloads standard-readme compliant package license make a pull request

Get access to your environment configuration

Table of Contents

Install

This project uses node and npm.

$ npm install @tiaanduplessis/env
$ # OR
$ yarn add @tiaanduplessis/env

Usage


const env = require('@tiaanduplessis/env')()

// Optionally specify a file name (default .env) and additional environment variables
const env2 = require('@tiaanduplessis/env')('.bar', {
  NAME: 'Tiaan',
  SURNAME: 'du Plessis'
})

// in A example .env file:
// FOO=1234
//

console.log(env.get('foo'), env.get('FOO')) // 1234 1234
env.set('foo', 555, true) // Overwrite FOO's value
env.set('foo', 888) // Will not be set, overwrite flag needed
console.log(env.get('foo'), env.get('FOO')) // 555 555

// Get access to variables on process.env
console.log(process.env.HOME, env.get('HOME')) // /Users/tiaan /Users/tiaan

// process.env is extended with variables from .env
// These variables are also updated when set
console.log(process.env.FOO) // 555
env.set('foo', 999, true)
console.log(process.env.FOO) // 999


env2.get(['name', 'surname']) // ['Tiaan', 'du Plessis']

Contribute

  1. Fork it and create your feature branch: git checkout -b my-new-feature
  2. Commit your changes: git commit -am 'Add some feature'
  3. Push to the branch: git push origin my-new-feature
  4. Submit a pull request

License

MIT

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.