envalid
Validates and sanitizes environment variables at startup, failing fast with clear error messages.
Official Documentation ↗v9.0.0. Check the official docs for the latest API surface.Installation
npm install envalidMethods
No methods match this filter.
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.
- By default, cleanEnv() will log an error message and exit (in Node) or throw (in browser) if any required env vars are missing or invalid. (https://cdn.jsdelivr.net/gh/af/envalid@latest/README.md)
- Error Reporting By default, if any required environment variables are missing or have invalid values, Envalid will log a message and call process.exit(1). (https://cdn.jsdelivr.net/gh/af/envalid@latest/README.md)
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.
- You can use this custom escape hatch to transform the output however you wish. (https://cdn.jsdelivr.net/gh/af/envalid@latest/README.md)
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.
Report a problem with this API docOpens a pre-filled issue on GitHub.