Part 13 of 13 · ~1 min
Common Mistakes Worth Remembering
- Registering CORS middleware after the routes it needs to apply to.
- Forgetting to call
next() (Express) — the request hangs with no response and no error.
- Putting expensive work (e.g. a database call, a network request) in middleware that runs on every request, including ones that don't need it.
- Assuming middleware order doesn't matter because "it's just logging" — even logging middleware placed after auth won't log requests that got rejected before reaching it.
- In Express specifically, forgetting that a rejected Promise inside an
async handler isn't automatically caught — it must be forwarded to next(err) explicitly.
- Registering "wraps the final response" middleware (compression, response-time headers) too late in the list, so it never actually wraps the code producing that response.
- Doing one-time setup (opening a connection, loading a file) inside the per-request call instead of the constructor/startup phase, repeating expensive work on every single request.
See ASP.NET Core's version of this pipeline in real context in Building REST APIs with ASP.NET Core, and Django's middleware stack covered as part of the broader framework in Django Fundamentals. Try building a short middleware chain yourself in the code lab.