1.0.11 • Published 7 years ago

env-helper v1.0.11

Weekly downloads
3
License
ISC
Repository
github
Last release
7 years ago

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'
1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago