Next.jsMedium

What are Edge API Routes?

Edge API Routes are API endpoints that run on the Edge Runtime, a lightweight V8-isolate environment with Web APIs only, by exporting runtime = 'edge'. They promised fast cold starts close to users, but in current Next.js the Edge Runtime is deprecated for routes: the docs say to remove the runtime export and use the default Node.js runtime.

How they worked

  • Pages Router: export const config = { runtime: 'edge' } in pages/api/*.
  • App Router: export const runtime = 'edge' in route.ts.
  • Handlers used Web Request/Response; no fs, no native modules, no require, limited bundle size.

Why they fell out of favor

  • Many npm packages (database drivers, auth libraries, image tools) depend on Node.js APIs.
  • Edge functions far from the database added latency for every query, wiping out the cold-start gain.
  • No ISR on the Edge runtime, smaller code size limits and harder debugging.
  • Hosting platforms improved Node.js cold starts (for example Vercel's Fluid compute), narrowing the gap.

Current guidance (Next.js 16)

  • runtime = 'edge' is deprecated for pages, layouts and Route Handlers.
  • Cache Components does not support the runtime export at all.
  • proxy.ts (formerly middleware) runs on Node.js and cannot be configured. The deprecated middleware.ts still supports the Edge runtime for apps that need it.
  • For "edge" behavior such as geo redirects, use Proxy, CDN caching of prerendered output, or your platform's region settings (preferredRegion).

Interview framing

Explain what the Edge runtime is, its trade-offs, and that today the default answer is the Node.js runtime with good caching.

Code example

tsx
1// Legacy: app/api/geo/route.ts (deprecated pattern)
2// export const runtime = "edge";
3// export function GET(request: Request) {
4// return Response.json({ country: request.headers.get("x-vercel-ip-country") });
5// }
6
7// Current: same handler on the default Node.js runtime (no runtime export)
8export function GET(request: Request) {
9 return Response.json({
10 country: request.headers.get("x-vercel-ip-country") ?? "unknown",
11 });
12}
13
14// If you need low latency near the data, pin the region instead:
15// export const preferredRegion = "iad1";
16
17// Edge-style request logic belongs in proxy.ts:
18// export function proxy(req: NextRequest) { /* geo redirect */ }

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.

Open in study app