- Notifications
You must be signed in to change notification settings - Fork0
get value of an environment variable; throw if undefined or empty string
License
jcoreio/require-env
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A simple function that returns the value of an environment variable, butthrows if it's not a non-empty string.Logs the entire environment toconsole.error to aid debugging.Flow type defs included.
npm install --save @jcoreio/require-env
varrequireEnv=require('require-env')varFOO=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 inprocess.env, but you can override this by passing the environmenthash as the second argument:
varenvironment={ ...process.env, ...require('./defaultEnv.js')}varFOO=requireEnv('FOO',environment)
defaultenv- fantastic CLI/Node API for loading default environment variable values
In the pastErrors thrown had all environment variables in theirmessages.I've since realized this was a huge security risk when error messages are sentfrom server to client. Now the message and environment variables are printed toconsole.error. You can customize this by monkeypatching therequire('@jcoreio/require-env').logError function.
About
get value of an environment variable; throw if undefined or empty string
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.