Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@cubos/env

lbguilherme2.1k2.0.0TypeScript support: included

Strict process.env

readme

npm version

@cubos/env

This module allow accessing ENV variables in a easier way than standard process.env.SOMETHING. The rational is that when you are accessing a configuration variable you expect it to exist. Sometimes it isn't possible to define a default value.

const something = process.env.SOMETHING; // string | undefined
// You must check before using this var.
if (!something) {
  throw new Error("You must define 'SOMETHING'");
}
import env from "@cubos/env";

// This will throw if $SOMETHING is not defined.
const something = env.SOMETHING; // string

Note: if you want to allow the var to be optional and set a default value, do:

const something = process.env.SOMETHING ?? "default value"; // string