Skip to content

equalsEnv

The equalsEnv function checks if the value of an environment variable matches the expected value.

Syntax

typescript
equalsEnv(key: string, expected: string | string[]): boolean;

Parameters

NameTypeDescription
keystringThe name of the environment variable to check
expectedstring | string[]The expected value or list of values for comparison

Returns

TypeDescription
booleantrue if the environment variable matches the expected value, false otherwise

Examples

typescript
equalsEnv("NODE_ENV", "production");
// => true or false

equalsEnv("NODE_ENV", ["development", "test"]);
// => true if NODE_ENV is "development" or "test"

Notes

  • Uses the getEnv function to retrieve the environment variable value.
  • Allows comparison with multiple expected values using an array.

References

Released under the MIT License.