I’ve spent half an hour trying to debug why the client was getting a 404 response back, and it turns out the cause was because we didn’t have a middleware in place to close the request (e.g.
res.end()). In other words, the last middleware in the stack called
next() but there wasn’t any more middleware to handle the request, so Express sent a 404 response.
I don’t think this should be the default behaviour, as this is clearly a case of programmer error. As such, I think express should throw an error instead, so that we can be made aware of the issue and add correct middleware in place or otherwise handle the error.
Silently responding with a 404 makes a developer hunt their own middleware stack first to see if and why they are terminating the request with a 404, which they aren’t.