Skip to content

Instantly share code, notes, and snippets.

@kubp
Created November 12, 2015 18:05
Show Gist options
  • Save kubp/bfbfa574f4c0849cad93 to your computer and use it in GitHub Desktop.
Save kubp/bfbfa574f4c0849cad93 to your computer and use it in GitHub Desktop.
Node Express 404 handler
app.use(function(req, res, next) {
var fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl;
if (app.get('env') == 'production') {
winston.info("404 - " + fullUrl);
} else {
console.log('\x1b[31m', '404', '\x1b[32m', fullUrl, '\x1b[0m');
}
res.status(404);
res.render("404");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment