Software Engineering ยท APIs & Systems
A function that runs in between an incoming request and the final handler, used to add cross-cutting behavior like logging, auth checks, or parsing.
Example: An Express middleware that checks for a valid auth token on every request before it reaches the route handler.
In practice: Middleware chains run in order, so bugs from misordering are common โ an auth check placed after a logging middleware that reads request data can behave differently than expected.