Now, we can finally get back to the generated app.js, the 404 Error page not found, and any other errors the application might want to show to the user.
A middleware function indicates an error by passing a value to the next function call. Once Express sees an error, it will skip any remaining non-error routing, and it will only pass it to error handlers instead. An error handler function has a different signature than what we saw earlier.
In app.js, which we're examining, this is our error handler:
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
Error handler functions take four parameters, with err added to the familiar req, res, and next. For this handler, we use res.status to set the HTTP response status code, and we use res.render to format an HTML response using the views/error.hbs template. The res.render function takes data, rendering it with a template to produce HTML.
This means any error in our application will land here, bypassing any remaining middleware functions.