1.0.11 • Published 8 years ago
env-helper v1.0.11
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 the
keyvalue isn't found in the environment dictionary, this value is returned. - envObject (Object): The object (dictionary) to query for environment configuration variables. Defaults to
process.envif not provided.
Examples:
process.env.MONGO_URL = undefined
let mongo_url = env('MONGO_URL', 'mongodb://localhost:27017/admin')
// 'mongodb://localhost:27017/admin'process.env.MONGO_URL = 'mongodb://localhost:3001'
let mongo_url = env('MONGO_URL', 'mongodb://localhost:27017/admin')
// 'mongodb://localhost:3001'Nested object queries also work:
process.env.PROD.MONGO_URL = 'mongodb://localhost:1234'
let mongo_url = env('PROD.MONGO_URL', 'mongodb://localhost:27017/admin')
// 'mongodb://localhost:1234'