Instructions
When to Use
- Use when deciding Edge vs Node for a Route Handler or middleware.
- Prefer
next-server-patternsfor general App Router placement. - Prefer
auth-handbookif Edge auth APIs are the blocker.
Explain Edge vs Node runtimes in Next.js for the user’s code. Always verify against the installed Next version.
Decision matrix
| Workload | Prefer | Why |
|---|---|---|
| Middleware auth gate (coarse) | Edge | Default; keep tiny |
Prisma / native addons / fs |
Node | Typical Edge blockers |
| Long-lived WS/SSE fan-out | Node (realtime-handbook) |
Connection lifespan |
| Geo/header rewrite only | Edge | Low I/O |
| Heavy crypto / PDF / image ops | Node | CPU + APIs |
- Flag imports:
fs, native Prisma client, somecryptopatterns, large WASM - usually Node. - Middleware defaults to Edge - keep fast; no heavy I/O or DB.
- Route segment config
runtime = 'edge' | 'nodejs'- justify per route. - Env: Edge often inlines
process.env- secrets risk; public env only on Edge unless you know the deploy model. - Split: Edge validates + forwards to a Node Route Handler / internal API when needed.
- Observability: many APM exporters are Node-only - split instrumentation (
observability-handbook).
Outcomes
- Table: file → current runtime → recommended runtime → blockers.
Output Rules
Link to Next docs concepts by name; no fabricated API lists - say “verify against installed Next version”.
Scope and boundaries
- In scope: runtime choice, import restrictions, split patterns.
- Out of scope: Cloudflare Workers specifics unless the user deploys there.
Safety
- Read-only; warn on secret exposure on Edge.
Troubleshooting
- Prisma on Edge: Data Proxy / driver adapter or move to Node - state tradeoffs.
- Bundle too large for Edge: move dependencies behind a Node route.
- Middleware timeout: shrink work; push DB to Node.
Related skills
next-server-patterns- Node vs Edge splitserver-caching-handbook- edge-compatible cachesauth-handbook- session checks on Edge limitsrealtime-handbook- long-lived connections
GitHub: https://github.com/bh611627/skillcodex/tree/main/skills/edge-runtime-handbook/SKILL.md
npm: https://www.npmjs.com/package/@skillcodex/skills