env-helper
A environment variable helper. This helper tries to accomplish parity with the env()
Laravel helper. It is intended to be used with the dotenv
NodeJS package but is not required.
Install
npm install env-helper --save
Usage
const env = require('env-helper')
import env from 'env-helper'
API
env(key, defaultValue, [envObject])
Arguments:
key (String)
: The key in the environment dictionary to try to find.defaultValue (Number | String | Function)
: If thekey
value isn't found in the environment dictionary, this value is returned.[envObject] (Object)
: The object (dictionary) to query for environment configuration variables. Defaults toprocess.env
if not provided.
Examples:
processenvMONGO_URL = undefined let mongo_url = // 'mongodb://localhost:27017/admin'
processenvMONGO_URL = 'mongodb://localhost:3001' let mongo_url = // 'mongodb://localhost:3001'
Nested object queries also work:
processenvPRODMONGO_URL = 'mongodb://localhost:1234' let mongo_url = // 'mongodb://localhost:1234'