Next.js 57: Edge vs Node.js Runtime
easy⏱ 5 mincoursenextjs
Two runtimes, two tradeoffs
Edge functions run in a lightweight V8 isolate replicated across many regions — no full Node.js process to boot, so cold starts are fast, but you lose access to Node-only APIs (fs, crypto's full surface, native addons). Node.js functions run in a real Node.js process — everything works, but spinning one up from cold costs more time.
// app/api/hello/route.ts
export const runtime = "edge"; // or "nodejs" (the default)
export async function GET() {
return Response.json({ message: "Hello from the edge!" });
}
Pick the right runtime
ANSWERS.diskRead is already set to 'nodejs' (reading a file needs fs, which is Node-only) and ANSWERS.geoRedirect to 'edge' (a lightweight redirect wants Edge's fast cold start) — confirm both show 'Correct' below. Try flipping one and see the explanation change.
Not every route needs edge
Edge's fast cold start mostly matters for latency-sensitive, high-traffic entry points — auth checks, redirects, personalization. A background job or anything using a Node-only library (an image-processing package, a database driver requiring TCP sockets) should stay on the Node.js runtime, cold start or not.