CodePark/ questions / Env & deployment
START PRACTICINGPRACTICE
Frontend question · Next.js › Env & deployment

Compare the Edge and Node.js runtimes in Next.js.

Node.js is the default runtime with full API support. Edge is a lighter runtime that starts fast but supports fewer APIs.

The Node.js runtime is the default for pages, Route Handlers and Server Actions. It has the full Node API and the npm ecosystem. That includes file system access and most database drivers.

The Edge runtime is a lighter environment based on Web APIs, such as fetch, Request and Response.

  • It starts quickly and can run close to users.
  • It doesn't support many Node APIs, native modules or some libraries.
  • It has code size limits.
  • You opt in per route with export const runtime = "edge".

Middleware history:

  • Middleware first ran only on the Edge runtime.
  • Next.js 15.5 added Node.js support.
  • In Next.js 16, middleware is renamed proxy.ts and runs on Node.js.

For most apps, Node.js is the safer default. Use Edge only for small, latency-sensitive code with no Node dependencies.

  • Node.js is the default runtime with full API support.
  • Edge supports Web APIs only, starts fast and has size limits.
  • Opt in to Edge with export const runtime = "edge".
  • Many npm packages and database drivers need Node.js.
  • In Next.js 16, proxy.ts runs on Node.js.