Does Next.js provide system environment variables?

HEAD
44ab1beSupport MPA navigations in `instant()` (#89469)
This post might have stale content, as HEAD is 578 commits ahead.

does next have system environment variables? env vars that are always provided by the framework

Avatar of anthropic/claude-opus-4.5
Claude Opus 4.5
commented

Now I have a complete picture. Let me summarize what I found:


##Yes! Next.js provides several system environment variables

Next.js automatically sets up environment variables that are always available in your application. Here's the comprehensive list from the source code (packages/next/src/build/define-env.ts):

###Core System Variables

VariableDescription
process.env.NODE_ENVAutomatically set to 'development' for next dev or 'production' for next build/next start. Allowed values: production, development, test.
process.env.NEXT_RUNTIMEIndicates the current runtime: 'edge', 'nodejs', or '' (empty for client).

###Internal Next.js Variables (prefixed with __NEXT_)

These are primarily for internal use but are always defined:

VariablePurpose
__NEXT_BASE_PATHThe configured basePath from next.config.js
__NEXT_TRAILING_SLASHWhether trailing slash is enabled
__NEXT_I18N_SUPPORTWhether i18n is enabled
__NEXT_I18N_CONFIGThe i18n configuration
__NEXT_IMAGE_OPTSImage optimization settings
__NEXT_ROUTER_BASEPATHRouter's base path
__NEXT_ASSET_PREFIXThe configured asset prefix
__NEXT_CROSS_ORIGINCross-origin setting
__NEXT_STRICT_MODEReact Strict Mode setting
__NEXT_PPRPartial Prerendering enabled
__NEXT_HAS_REWRITESWhether rewrites are configured
__NEXT_CONFIG_OUTPUTThe output mode (standalone, export, etc.)

###Build-time Variables

VariablePurpose
process.env.TURBOPACKtrue when using Turbopack
process.env.__NEXT_BUNDLER'Turbopack', 'Rspack', or 'Webpack'
process.env.NEXT_DEPLOYMENT_IDDeployment identifier (if configured)

###How NODE_ENV is Set (from docs)

From packages/next/src/build/define-env.ts:

'process.env.NODE_ENV':
  dev || config.experimental.allowDevelopmentBuild
    ? 'development'
    : 'production',
  • Running next devNODE_ENV = 'development'
  • Running next build or next startNODE_ENV = 'production'
  • Running tests with NODE_ENV=testNODE_ENV = 'test'

###NEXT_PUBLIC_ Prefix

Any environment variable prefixed with NEXT_PUBLIC_ is automatically exposed to the browser (client-side). These are collected at build time from process.env (see packages/next/src/lib/static-env.ts).

###Important Notes

  1. Reserved prefixes: You cannot use NODE_* or __* prefixes in the env config in next.config.js - these are protected.
  2. NEXT_RUNTIME is also protected and cannot be overridden in config.
  3. Most __NEXT_* variables are internal and shouldn't be relied upon in user code as they may change between versions.

END OF POST

Does Next.js provide system environment variables? — vercel/next.js