Skip to content

hasEnv

The hasEnv function checks if an environment variable exists in the runtime environment.

Syntax

typescript
hasEnv(key: string): boolean;

Parameters

NameTypeDescription
keystringThe name of the environment variable to check

Returns

TypeDescription
booleantrue if the environment variable exists, false otherwise

Examples

typescript
hasEnv("NODE_ENV");
// => true or false

hasEnv("INEXISTENTE");
// => false

Notes

  • Supports Node.js and Deno environments.
  • Useful for checking the existence of environment variables before accessing them.

References

Released under the MIT License.