Get unlimited public & private packages + team-based management with npm Teams.Learn more »

@mikestopcontinues/env

1.0.2 • Public • Published

env

A handy utility for working with environments and env variables.

Installation

> npm install --save @mikestopcontinues/env

Usage

import env from '@mikestopcontinues/env';

environments

import env from '@mikestopcontinues/env';
 
// get current NODE_ENV
env.is(); // = 'development', if set
env.is(); // throws error, if unset
 
// test current environment contained in list
env.in('development'); // = true
env.in('development', 'testing'); // = true
env.in('testing'); // = false
 
// matches wildcards
env.in('dev*'); // = true
env.in('*elop*'); // = true
env.in('*ment'); // = true
env.in('dev*', 'test*'); // = true
env.in('test*'); // = false
 
// allowing for finegrained control
env.in('staging:fake-data');
env.in('staging:real-data');
env.in('staging*');
 
env.in('testing:fake-data');
env.in('testing:real-data');
env.in('*fake-data');

Environment variables

// get environment vars, with fallbacks
env.get('SET_VAR'); // = 'actual'
env.get('UNSET_VAR'); // = undefined
 
env.get('UNSET_VAR', 'fallback'); // = 'fallback'
 
env.get([
  'SET_VAR',
  'UNSET_VAR',
], 'fallback'); // ['actual', 'fallback']
 
env.get({
  SET_VAR: 'fallback',
  UNSET_VAR: 'fallback',
}); // {SET_VAR: 'actual', UNSET_VAR: 'fallback'}
 
// check that all environment vars exist
env.has('SET_VAR'); // = true
env.has('SET_VAR', 'UNSET_VAR'); // = false
 
// ensures that all environment vars exist
env.needs('SET_VAR'); // = undefined
env.needs('SET_VAR', 'UNSET_VAR'); // throws error

Install

npm i @mikestopcontinues/env

DownloadsWeekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

7.42 kB

Total Files

4

Last publish

Collaborators

  • avatar