Where Next.js Middleware executes and Edge Runtime limits
Tests your grasp of Edge Runtime constraints. Middleware runs at the Edge before route matching, with no Node.js APIs, require, Buffer, or dynamic eval, only Web APIs. Red flag: treating it as Node.js and suggesting fs or npm packages.
What's really being asked
This question probes whether you understand the architectural boundary between the Edge Runtime and the Node.js runtime in Next.js. Middleware is not just another server function; it runs in a highly constrained, V8-isolate-like environment before the request ever reaches the application router or the Node.js server. Interviewers want to see that you know which APIs disappear, why package selection matters, and how this shapes what Middleware can realistically do.
A GOOD ANSWER COVERS four things in order. First, location: Middleware executes exclusively in the Edge Runtime, before route matching and before any page or API route logic in the Node.js runtime. Second, missing Node.js APIs: there is no filesystem access via fs or path, no Node.js crypto module, no Buffer, no process beyond process.env, and no CommonJS require. Third, dynamic code evaluation is blocked: eval, new Function, and WebAssembly.compile are disabled at runtime. Fourth, what remains available: standard Web APIs including fetch, Request, Response, Headers, Web Crypto, streams, timers, URLPattern, and the AsyncLocalStorage polyfill, plus environment variables via process.env. You should also mention that only ES modules are supported and that ISR is not available in the Edge Runtime.
COMMON WRONG ANSWERS include claiming Middleware runs on the standard Node.js server alongside pages, saying you can use fs to read a local config file, importing arbitrary npm packages that rely on native Node.js modules, or attempting to use eval for dynamic configuration. Another red flag is treating the Edge Runtime as simply a faster Node.js rather than a distinct Web-API subset. Candidates sometimes assume that because process.env works, all Node.js process methods are available, which is incorrect.
LIKELY FOLLOW-UPS include asking how you would share authentication logic between Middleware and a Node.js API route, which forces a discussion of using Web Crypto instead of Node.js crypto or jsonwebtoken. They might also ask how to work around a library that only runs in Node.js, where the correct path is to avoid it in Middleware or move that work to a Route Handler. A performance angle is also common: because Edge has faster cold starts, interviewers may ask when to prefer Edge over Node.js for Route Handlers.
ONE CONCRETE EXAMPLE is rewriting an auth check. A candidate might try to import the jsonwebtoken npm package inside middleware.ts to verify a JWT. This fails because jsonwebtoken depends on Node.js crypto and Buffer. The correct approach is to use the Web Crypto API directly or a lightweight library built for Edge runtimes, verifying the JWT via SubtleCrypto and returning NextResponse.rewrite or NextResponse.redirect based on the payload.
Interview question
You need to verify a JWT inside Next.js Middleware. Which approach works correctly in the Edge Runtime?
- a.Use process.env for the secret and Buffer.from to decode the base64 payload before verifying
- b.Use the Web Crypto API to verify the JWT signature using the secret from process.envCorrect
- c.Import the jsonwebtoken library and call jwt.verify with the secret from process.env
- d.Use the Node.js crypto module to verify the signature with the secret from process.env
Why? this is the answer
The Edge Runtime supports Web Crypto and process.env, but it lacks Node.js crypto, Buffer, and the jsonwebtoken dependency chain. Option C is tempting because jsonwebtoken is standard in Node.js, yet it relies on native modules that are unavailable in the Edge isolate.
Just read this? Test yourself on what you have been reading.
Read the original → vercel-next-js.mintlify.app
- #next.js
- #middleware
- #edge runtime
- #react
- #vercel
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on next.js — each one lists the topics its interview covers.
See open roles