1app.use(function(req, res, next){
2 res.status(404);
3
4 // respond with html page
5 if (req.accepts('html')) {
6 res.render('404', { url: req.url });
7 return;
8 }
9
10 // respond with json
11 if (req.accepts('json')) {
12 res.send({ error: 'Not found' });
13 return;
14 }
15
16 // default to plain-text. send()
17 res.type('txt').send('Not found');
18});