Middleware registered in the wrong order
Locate the failed assumption, reproduce it, then repair the cause.
What actually caused it
Express runs app.use in the order you registered them. Each one may call next or end the response. If an earlier function sends a status and a body, every function registered after it is skipped, including a logger you thought would always run. The function bodies can be correct and the route can be correct. The bug is only the sequence of app.use calls. A guard that rejects the request before the logger, or a parser registered after the route that needed the parsed body, fails the same way: later code never sees the request.
Minimal reproduction
Auth ends the response before the logger
app.use((req, res, next) => {
res.status(401).send('auth');
});
app.use((req, res, next) => {
console.log('log');
next();
});
The logger is registered, but auth already sent the response.
The fix
List the in the order they must see the request. Parsing and logging that should always happen belong before a guard that might send a response. After you move a line, send one request and read which steps actually ran. If the body or the status changed, the new order is the behavior. Do not add a second copy of the skipped function below the guard and expect both copies to run. The first response still ends the chain.
Log first, then decide
app.use((req, res, next) => {
console.log('log');
next();
});
app.use((req, res, next) => {
res.status(401).send('auth');
});
next() lets the request reach the next .