glossary2 min read

Middleware Explained

Middleware functions process requests between client and server logic.

Middleware sits between incoming requests and your route handlers. Each middleware function can: inspect/modify the request, inspect/modify the response, call the next middleware, or end the request. Common uses: authentication (verify JWT), logging, CORS headers, rate limiting, body parsing, error handling. In Express: app.use(middleware). In Next.js: middleware.ts at the root.