The Edge Runtime is a lightweight JavaScript runtime that runs code closer to your users, at the edge of the network.
Benefits
- Lower latency: Code runs in data centers near users.
- Faster cold starts: Lighter than Node.js.
- Global distribution: Automatic worldwide deployment.
Enabling Edge Runtime
For Route Handlers:
typescriptexport const runtime = 'edge'; export async function GET() { return Response.json({ message: 'Hello from the edge!' }); }
For Pages/Layouts:
typescriptexport const runtime = 'edge'; export default function Page() { return <h1>Edge-rendered page</h1>; }
Limitations
The Edge Runtime doesn't have access to all Node.js APIs:
- ❌
fs(filesystem) - ❌
child_process - ❌ Native Node modules
- ✅
fetch - ✅
crypto.subtle - ✅
TextEncoder/Decoder