API Reference

envalid

Validates and sanitizes environment variables at startup, failing fast with clear error messages.

Official Documentation ↗
CompatibilityThis documentation covers version v9.0.0. Check the official docs for the latest API surface.

Installation

npmnpm install envalid

Methods

envalid parses process.env through typed validators, returning a frozen, typed object.

Key Features

  • Typed validators for str, num, port, and more
  • Fail-fast with combined error output
  • Frozen result discourages mutation

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

Errors

The following points are quoted verbatim from the official documentation. 来源:https://cdn.jsdelivr.net/gh/af/envalid@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:49:24.379Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

Security notes

Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://cdn.jsdelivr.net/gh/af/envalid@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:49:24.379Z.

FAQ

What happens with a missing required var?
cleanEnv throws at startup listing every invalid variable together, so you fix them in one pass instead of one error at a time.
Can I skip validation in tests?
Yes. Pass options such as { reporter: null } or provide a per-test environment object instead of process.env.
Is the result mutable?
No. The returned object is frozen, which prevents accidental runtime reassignment of configuration.