process.env
The object in Node.js that holds the process's environment variables, with every value stored as a string.
In more detail
Read settings with process.env.PORT and convert them yourself, for example with parseInt, since they are always strings or undefined. Child processes inherit a copy unless you pass a different env.
Examples
if (process.env.NEXT_RUNTIME === 'nodejs') { /* Node-only setup */ }Next.js inlines NEXT_PUBLIC_ variables into client bundles at build time; other variables stay on the server.declare global { namespace NodeJS { interface ProcessEnv { DATABASE_URL: string; PORT: string } } }Related terms
- environment variable — A named setting such as PORT=8000 that a program reads from its surroundings when it starts.
- NEXT_RUNTIME — An environment variable Next.js sets to nodejs or edge so code can tell which runtime it is running in.
- --env-file — A Node.js command-line flag that loads variables from a .env file into process.env before your code runs, with no package needed.
- process object — The global object in Node.js that describes the running process and lets you read its environment and arguments, measure its memory, listen for signals and exit.
- global augmentation — Adding types to global objects such as Window or NodeJS.ProcessEnv with a declare global { } block inside a module.
- Node.js — A program that runs JavaScript outside the web browser, used mainly to build servers, command-line tools and back-end services.
Taught in
- Instrumentation: OpenTelemetry & Performance Spans — Next.js 15 & Modern App Router Architecture
- Runtime Configuration: CLI Flags & Native --env-file — Node.js Internals & Backend Services
- Verify Your Environment: Running tsc And Bun TypeScript — Production TypeScript
- Literal Types: String, Number, Boolean Literals And const — Production TypeScript
- Declaration Files, Ambient Namespaces And Module Augmentation — Production TypeScript