Joe Hart Joe Hart - 24 days ago 6
Node.js Question

Why is express error handling 404 on all routes, even ones that work?

So I've set up a blank brand new express app using the express generator.

I added a console.log to the error handler:

// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error ='env') === 'development' ? err : {};
console.log(err); //<-- This is the added line
// render the error page
res.status(err.status || 500);

And then when hitting the index of my app I get this in the console:

GET / 200 9.521 ms - 170
GET /stylesheets/style.css 200 2.099 ms - 111
{ [Error: Not Found] status: 404 }

Surely this code shouldn't even be called when a successful route is it? Is this meant to happen?


My guess is that the request that's causing the 404 is for /favicon.ico. The other requests have been handled successfully (hence the 200 status that gets logged, right after the request path).