
Kim JeongHyeonFrontend Focused Fullstack Developer

Edge Runtime의 장단점, Middleware 활용법, Node.js Runtime과의 비교를 정리합니다.
Edge Runtime brings your code closer to users. Here's how to use it effectively with Next.js.
Edge functions run on Vercel's global network — not in a single region like traditional serverless. This means lower latency for users worldwide.
// app/api/geo/route.ts
export const runtime = "edge";
export function GET(request: Request) {
const country = request.headers.get("x-vercel-ip-country") ?? "unknown";
return Response.json({ country });
}| Feature | Edge | Node.js |
|---|---|---|
| Cold start | ~0ms | 250ms+ |
| Max duration | 30s | 300s |
| File system | No | Yes |
| npm packages | Limited | Full |
| Global latency | Low | Regional |
Middleware always runs on the Edge. Use it for auth checks, redirects, and A/B testing:
// middleware.ts
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export function middleware(request: NextRequest) {
const session = request.cookies.get("session");
if (request.nextUrl.pathname.startsWith("/admin") && !session) {
return NextResponse.redirect(new URL("/login", request.url));
}
return NextResponse.next();
}
export const config = {
matcher: ["/admin/:path*"],
};fs, path, crypto (use Web Crypto instead)