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

Node.jsEdge
Cold startSlowerFaster
Node.js APIsFullNone
node_modulesAllES Modules only (no native addons)
StreamingYesYes
ISRYesNo

Setting the runtime

Specify the runtime in a Route Handler or layout/page segment using the runtime export:
app/api/route.ts
export const runtime = 'edge'
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

APIDescription
BlobRepresents a blob
fetchFetches a resource
FetchEventRepresents a fetch event
FileRepresents a file
FormDataRepresents form data
HeadersRepresents HTTP headers
RequestRepresents an HTTP request
ResponseRepresents an HTTP response
URLSearchParamsRepresents URL search parameters
WebSocketRepresents a WebSocket connection

Encoding APIs

APIDescription
atobDecodes a base-64 encoded string
btoaEncodes a string in base-64
TextDecoderDecodes a Uint8Array into a string
TextDecoderStreamChainable decoder for streams
TextEncoderEncodes a string into a Uint8Array
TextEncoderStreamChainable encoder for streams

Stream APIs

APIDescription
ReadableStreamRepresents a readable stream
ReadableStreamBYOBReaderReader for a ReadableStream
ReadableStreamDefaultReaderDefault reader for a ReadableStream
TransformStreamRepresents a transform stream
WritableStreamRepresents a writable stream
WritableStreamDefaultWriterWriter for a WritableStream

Crypto APIs

APIDescription
cryptoAccess to platform cryptographic functions
CryptoKeyRepresents a cryptographic key
SubtleCryptoLow-level cryptographic primitives (hashing, signing, encryption)

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

const value = process.env.MY_VAR
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:
APIDescription
evalEvaluates a JavaScript string as code
new Function(code)Creates a function from a string
WebAssembly.compileCompiles a WASM module from a buffer
WebAssembly.instantiateCompiles and instantiates a WASM module from a buffer

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
export const config = {
  unstable_allowDynamic: [
    '/lib/utilities.js',
    '**/node_modules/function-bind/**',
  ],
}
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

VersionChanges
v12.0.0Edge Runtime introduced

Build docs developers (and LLMs) love