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' }inpages/api/*. - App Router:
export const runtime = 'edge'inroute.ts. - Handlers used Web
Request/Response; nofs, no native modules, norequire, 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
runtimeexport at all. proxy.ts(formerly middleware) runs on Node.js and cannot be configured. The deprecatedmiddleware.tsstill 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// }67// 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}1314// If you need low latency near the data, pin the region instead:15// export const preferredRegion = "iad1";1617// 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.