Skip to main content
Next.js provides two server runtimes:
  • Node.js Runtime (default): full Node.js API surface, used for rendering and route handlers.
  • Edge Runtime: a subset of Web APIs, optimized for low-latency responses at the edge. Used in Middleware.

Choosing a runtime

Setting the runtime

Specify the runtime in a Route Handler or layout/page segment using the runtime export:
app/api/route.ts
The value must be 'edge' or 'nodejs'. When omitted, the Node.js runtime is used.
ISR (Incremental Static Regeneration) is not supported in the Edge Runtime.

Supported APIs

Network APIs

Encoding APIs

Stream APIs

Crypto APIs

Web Standard APIs

All standard JavaScript globals are available: Array, ArrayBuffer, Boolean, Date, Error, JSON, Map, Math, Number, Object, Promise, Proxy, RegExp, Set, String, Symbol, URL, URLPattern, URLSearchParams, WeakMap, WeakSet, WebAssembly, timer functions (clearInterval, clearTimeout, setInterval, setTimeout), encoding helpers (decodeURI, decodeURIComponent, encodeURI, encodeURIComponent), typed arrays, AbortController, console, DOMException, queueMicrotask, structuredClone, and more.

Next.js polyfills

  • AsyncLocalStorage (Node.js async_hooks API)

Environment variables

process.env is available in both next dev and next build.

Unsupported APIs

The following are not available in the Edge Runtime:
  • Native Node.js APIs (filesystem, crypto module, Buffer, etc.)
  • CommonJS require() — use ES module import instead
  • node_modules packages that use native Node.js APIs
The following JavaScript features are also disabled:

Allowing dynamic code evaluation

In rare cases where code contains unreachable dynamic evaluation, you can suppress the build error using unstable_allowDynamic in your Proxy config:
proxy.ts
If the allowed statements are executed at runtime on the Edge, they will throw a runtime error. Use unstable_allowDynamic only for code paths that are guaranteed not to execute.

Version history