Performance: Edge runtime vs Node.js runtime
This affects server response time and how fast the page starts rendering by choosing where and how code runs.
export const runtime = 'edge'; export async function GET() { // lightweight logic suitable for edge return new Response('Hello from Edge runtime'); }
export const runtime = 'nodejs'; export async function GET() { // heavy server logic return new Response('Hello from Node.js runtime'); }
| Pattern | Server Location | Network Latency | Response Time | Verdict |
|---|---|---|---|---|
| Node.js runtime | Central server | High for distant users | Slower due to centralized processing | [X] Bad for global users |
| Edge runtime | Distributed CDN nodes | Low due to proximity | Faster with reduced latency | [OK] Good for fast LCP |
Edge runtime in Next.js?runtime with value 'edge' or 'nodejs'.export const runtime = 'edge'; to set Edge runtime.export const runtime = 'edge' [OK]export const runtime = 'edge'; is set?export const runtime = 'edge';
export default function handler(req) {
return new Response('Hello from Edge!');
}runtime = 'edge', so it uses the Edge runtime environment.export const runtime = 'edge';
import fs from 'fs';
export default function handler(req) {
const data = fs.readFileSync('/data.txt', 'utf8');
return new Response(data);
}crypto for hashing and runs as close to users as possible. Which runtime should you choose and why?Pass the test and this pattern moves unknown