Edge vs Node.js Runtime

Speed vs Compatibility.

Next.js4 min readConcept 62 of 66

Two Server Environments

By default, Next.js executes Server Components and Route Handlers in a standard Node.js environment. This means you have full access to the filesystem (fs), cryptography (crypto), and heavy npm packages.

However, Next.js also supports the **Edge Runtime**—a stripped-down, ultra-fast V8 isolate environment (like Cloudflare Workers) that boots in milliseconds and runs globally close to the user.

The Trade-off

The Node.js runtime suffers from 'Cold Starts' (taking 1-3 seconds to boot up on the first request) and is usually centralized in one region (e.g., US-East).

The Edge runtime has **zero cold starts** and is deployed to hundreds of locations globally. It's the only runtime allowed for Middleware because Middleware must intercept every single request instantly.

The catch? Edge is heavily restricted. It does not support native Node.js APIs.

Opting into the Edge

You can switch any specific route or page to the Edge runtime by exporting a configuration variable.

typescript

// app/api/fast-route/route.ts

export const runtime = 'edge';

export async function GET() {

// This will run globally on the Edge Network.

return Response.json({ message: 'Instant!' });

}

Runtime Simulator

Toggle the runtime environment and watch how importing Node native modules behaves differently.

app/api/read/route.tsdefault (node)
import fs from 'fs';
import path from 'path';

export async function GET() {
  // Read a file from the disk
  const filePath = path.join(process.cwd(), 'data.json');
  const data = fs.readFileSync(filePath, 'utf8');

  return Response.json({ data });
}
Edge Runtime Crash (0ms)Error: Module "fs" not found. The Edge Runtime does not support Node.js native APIs.
Node.js Execution Success200 OK — File read successfully. (Noticeable Cold Start Delay)

Check yourself

Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.

  1. 1Why can't you use the 'fs' (filesystem) module inside Next.js Middleware?

Remember this

  • Node.js (Default): Full compatibility, centralized region, has cold starts.
  • Edge Runtime: Limited compatibility (Web APIs only), global distribution, zero cold starts.
  • Middleware strictly requires the Edge Runtime.
  • You can opt a Route Handler or Server Component into the Edge using export const runtime = 'edge';

Done with this concept?

Mark it complete to track your progress. No login needed.