Package Exports
- @humanwhocodes/env
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@humanwhocodes/env) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Env utility
If you find this useful, please consider supporting my work with a donation.
Description
A utility for verifying that environment variables are present in Node.js. The main use case is to easily throw an error when an environment variable is missing. This is most useful immediately after a Node.js program has been initiated, to fail fast and let you know that environment variables haven't been setup correctly.
Folder Structure
The most recent packages are found in these directories:
src- the implementation source codetests- tests for the implementation source code
Usage
You must be using Node.js to use this utility.
Install using [npm][npm] or [yarn][yarn]:
npm install @humanwhocodes/env --save
# or
yarn add @humanwhocodes/envImport into your Node.js project:
const { Env } = require("@humanwhocodes/env");After that, create a new instance of Env to start reading environment variables:
const env = new Env();
// read a variable and don't care if it's empty
const username = env.get("USERNAME");
// read a variable and user a default if empty
const username = env.get("USERNAME", "humanwhocodes");
// read a variable and throw an error if it doesn't exist
const username = env.require("USERNAME");