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

Taught in

References