get value of an environment variable; throw if undefined or empty string
npm install @jcoreio/require-env




A simple function that returns the value of an environment variable, but throws if it's not a non-empty string.
Logs the entire environment to console.error to aid debugging.
Flow type defs included.
``sh`
npm install --save @jcoreio/require-env
`js
var requireEnv = require('require-env')
var FOO = requireEnv('FOO')
// now you can be sure that FOO is a non-empty string, and Flow will trust that it is too.
`
By default it looks in process.env, but you can override this by passing the environment
hash as the second argument:
`js`
var environment = { ...process.env, ...require('./defaultEnv.js') }
var FOO = requireEnv('FOO', environment)
- defaultenv - fantastic CLI/Node API for loading default environment variable values
In the past Errors thrown had all environment variables in their messages.console.error
I've since realized this was a huge security risk when error messages are sent
from server to client. Now the message and environment variables are printed to. You can customize this by monkeypatching therequire('@jcoreio/require-env').logError` function.