This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

env-helper

1.0.11 • Public • Published

env-helper Build Status NPM version Size G-Zip Size

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 key value 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.env if 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'

Package Sidebar

Install

npm i env-helper

Weekly Downloads

0

Version

1.0.11

License

ISC

Last publish

Collaborators

  • br0p0p