Skip to the solution
MediumSystem Design5 min read

What runtimes does Next.js support (Node.js vs Edge runtime)?

137 views

The problem

Question presented to candidate: "What is the difference between the Node.js and Edge runtimes in Next.js, when would you have chosen Edge, and what is the recommendation today?"

What a strong answer should cover:

  • Node.js runtime: the default for pages, layouts, Route Handlers and, in Next.js 16, Proxy; full Node APIs and npm compatibility.
  • Edge runtime: a smaller runtime based on Web APIs, historically chosen for low latency and fast cold starts close to users.
  • Edge limits: no Node built-ins such as fs, restricted packages, size limits; the lab showed process.versions missing.
  • The Edge runtime is deprecated (16.3.4 and 16.4.2 both warn at build time), and on a page it disables static generation; with Cache Components any runtime export, even 'nodejs', fails the build.
  • The recommendation is the Node.js runtime everywhere, including proxy.ts, which now runs on Node by default.

Clarifying questions expected:

  • "Does the code need Node APIs or native packages?" β€” they only work on Node.js.
  • "Is the goal latency?" β€” caching and static rendering usually beat moving compute.

Code / implementation expected: Optional β€” the runtime export and what the build says.

  • nextjs
  • edge-runtime
  • nodejs-runtime
  • deployment

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

5 min read Β· 8 sections

Read the code

Removing the edge runtime and moving middleware to proxy
// Before (Next.js 14/15)
// app/api/geo/route.ts
export const runtime = "edge";
export async function GET() { return Response.json({ ok: true }); }

// After (Next.js 16): no runtime export, Node.js by default
export async function GET() { return Response.json({ ok: true }); }

// middleware.ts -> proxy.ts   (npx @next/codemod@canary middleware-to-proxy .)
import { NextRequest, NextResponse } from "next/server";
export function proxy(req: NextRequest) {
  return NextResponse.next();
}

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 91 of 129 in Next.js

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

All Next.js questions
Up nextMedium

What is the 'use client' directive and when do you need it?

Continue