envic

JSON, JSONIC or string environment variables


Keywords
json, jsonic, env, environment, config
License
MIT
Install
npm install envic@1.0.4

Documentation

envic

Humanized JSON, JSONIC or string environment variables.

Get strings and expanded JSON and JSONIC variables into objects, for environment keys for the passed key (ex humanized: Mongo URL).

Detection order

Install

npm i envic --save

Usage

var envic = require('envic')

console.log(envic('port'))       // default port or undefined
console.log(envic('port', 5000)) // default port or 5000
// instead of:
var mongourl = process.env.MONGO_URL || 'mongodb://localhost:27017/mydb'

// use:
var mongourl = envic('Mongo URL', 'mongodb://localhost:27017/mydb')

Matches keys: Mongo URL, MONGO_URL, mongo_url, mongoUrl, MONGOURL, MONGO-URL, mongo-url

JSON environment variables

Ex: env variable MAILGUN = {"apiKey":"key-DEFAULT_KEY", "domain":"myproject.mailgun.com"}

// instead of:
var mailgunConfig, defaultConfig = {apiKey: 'key-XXXXXXXXXXXXX', domain: 'example.mailgun.com'}
try {
  mailgunConfig = JSON.parse(process.env.MAILGUN)
} catch(e) {
  mailgunConfig = defaultConfig
}

// use: with default
var mailgunConfig = envic('MailGun', {apiKey: 'key-DEFAULT_KEY', domain: 'example.mailgun.com'})

JSONIC environment variables

JSONIC is simplifed JSON

Example:

`MAILGUN = 'apiKey:key-DEFAULT_KEY, domain:myproject.mailgun.com' node example.js`
var mailgunConfig = envic('Mail Gun')

License

MIT