Skip to content

cubos/node-env

This branch is 1 commit ahead of master.

Folders and files

NameName
Last commit message
Last commit date
Nov 30, 2023
Jan 19, 2021
Jul 1, 2022
Jan 19, 2021
Jan 19, 2021
Jan 19, 2021
Aug 16, 2022
Jan 19, 2021
Jul 1, 2022
Jan 19, 2021
Jul 1, 2022
Jul 1, 2022

Repository files navigation

@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";

const something = env.SOMETHING; // string
// It will throw if the var is not defined.

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