requireEnv()function

requireEnv(name: string, caller: AnyCaller = requireEnv): string
ParamType
namestring
Name of the environment variable to read. required
callerAnyCaller
Function to attribute a thrown error to (defaults to requireEnv). Defaults to requireEnv
Return
string
The variable's string value.
Throws
unknown
RequiredError if the variable is missing or process.env is unsupported.

Get a process.env variable safely in all environments, or throw RequiredError if it doesn't exist or this environment does not support process.env (i.e. web environments).

Examples

requireEnv("DATABASE_URL") // "postgres://..."