Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

get value of an environment variable; throw if undefined or empty string

License

NotificationsYou must be signed in to change notification settings

jcoreio/require-env

Repository files navigation

CircleCICoverage Statussemantic-releaseCommitizen friendlynpm version

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.

Usage

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)

See also

  • defaultenv - fantastic CLI/Node API for loading default environment variable values

Error messages

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

Stars

Watchers

Forks

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp