Next.js › Edge Runtime vs Node.js Runtime
How do you specify which runtime a specific route or middleware should use in Next.js?
IntermediateAnswer
You export a runtime constant set to either edge or nodejs from your route handler or page file, telling Next.js which environment to run that specific piece of code in, allowing you to mix and match runtimes across different parts of the same application based on their needs.
// app/api/fast-check/route.js
export const runtime = 'edge';
export async function GET() {
return Response.json({ status: 'ok' });
}Real-world example An application uses the Edge Runtime for a simple health check endpoint that needs to respond instantly worldwide, while keeping its main data processing routes on the Node.js Runtime.