CONVAR
Get configuration variable via config file, environment variable, package, npm or cli with optional required error handling
Install
npm install convar --save
Use
var convar = token = // e27d9f2a29b7
Required values pass in error message or Error
var convar = token = // e27d9f2a29b7 url =
Value via command line
node app.js --token e27d9f2a29b7 --node_env dev
Conditional flags
node app.js --debug
app.js
:
var convar = debug = // true
Value via environment variable
token=e27d9f2a29b7node_dev=dev node app.js
Ignore case
This will also work
TOKEN=e27d9f2a29b7NODE_ENV=dev
Value via JSON config
config='{ "token":"e27d9f2a29b7", "NODE_ENV":"dev" }'
JSONIC simplified JSON
Value viaconfig=token:e27d9f2a29b7,NODE_ENV:dev
JSONIC variables
JSON ornode app.js --config token:e27d9f2a29b7,NODE_ENV:dev --firebase url:https://example.firebaseio.com,token:e27d9f2a29b7e27d9f2a29b7
var convar = token = // e27d9f2a29b7 fbUrl = url // example.firebaseio.com
JSON config file
config.json
file:
"token": "e27d9f2a29b7" "NODE_ENV": "dev" "firebase": "url": "https://example.firebaseio.com" "token": "e27d9f2a29b7e27d9f2a29b7"
config
parameter is a file if it isn't JSON or JSONIC and a string that contains .json
node app.js --config config.json
Prefixed values
Example with yo_
prefix
node app.js --yo_token e27d9f2a29b7
Use
var convar = convarprefix'yo_'var token = // e27d9f2a29b7
Package values
var convar = console // 1.0.0