Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jcoreio/require-env

Package Overview
Dependencies
Maintainers
6
Versions
113
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jcoreio/require-env

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

  • 1.1.88
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
129
decreased by-40.83%
Maintainers
6
Weekly downloads
 
Created
Source

@jcoreio/require-env

CircleCI Coverage Status semantic-release Commitizen friendly npm version

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.

Usage

npm install --save @jcoreio/require-env
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:

var environment = {...process.env, ...require('./defaultEnv.js')}
var FOO = requireEnv('FOO', environment)

See also

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

Error messages

In the past Errors thrown had all environment variables in their messages. 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 console.error. You can customize this by monkeypatching the require('@jcoreio/require-env').logError function.

Keywords

FAQs

Package last updated on 10 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc