envic
v1.0.3
Published
JSON, JSONIC or string environment variables
Downloads
4
Maintainers
Readme
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
- Passed key (ex:
Mongo URL
) - Uppercase Underscored key (ex:
MONGO_URL
) - Lowercase Underscored key (ex:
mongo_url
) - Uppercase Camelized key (ex:
MONGOURL
) - Camelized key (ex:
MongoUrl
) - Uppercase Slugified key (ex:
MONGO-URL
) - Lowercase Slugified key (ex:
mongo-url
)
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