Documentation Index
Fetch the complete documentation index at: https://next-safe-env.dev/llms.txt
Use this file to discover all available pages before exploring further.
next-safe-env works equally well outside Next.js. In any Express server, Fastify app, CLI script, or background worker, you get the same validated, fully-typed env object with no framework-specific setup. Numeric variables like PORT come back as actual numbers, boolean flags are coerced from strings, and the process refuses to start if anything is misconfigured.
Create config/env.ts
Define your schema in a dedicated config file. Set
adapter: 'node' explicitly, or omit it and rely on auto-detection - when NEXT_RUNTIME is not set and no NEXT_PUBLIC_ keys are present, next-safe-env selects the node adapter automatically.next-safe-env validates what is already in process.env. It does not load .env files. Use dotenv or your platform’s native secret injection to populate process.env before createEnv runs.The node adapter
Thenode adapter is intentionally minimal. Both of its hooks - beforeValidate and afterValidate - are no-ops. Raw env values go in, validated and coerced values come out unchanged. There are no prefix rules, no key-stripping, and no browser-context checks. Every var from both server and client schemas is present in the returned object.
This makes the node adapter appropriate for any environment where you control the full process and want all variables available without restriction.
Auto-detection
When you omitadapter, next-safe-env selects the adapter based on the runtime environment:
| Condition | Adapter selected |
|---|---|
process is undefined or has no version | edge |
process.env.NEXT_RUNTIME is set | nextjs |
| Otherwise | node |
NEXT_RUNTIME is not set, node is always selected. Setting adapter: 'node' explicitly is recommended for clarity and to make your intent self-documenting.

