Handle 404 error with Express 4 : <p>I am using Express 4 and I have about 50 html pages. I'm trying to handle 404 errors but can't figure out how. I don't want to manually define all the routers within node. Is there a way to dynamically redirect to a 404 Jade template if a page doesn't exist?</p>

<p>I tried this code but didn't work:</p>

<pre><code>app.enable('verbose errors');
app.set('port', 3000);

app.use(express.static(__dirname + '/html/'));

var server = http.createServer(app);
server.listen(app.get('port'), function() {
    console.log('ONLINE !');
});

app.use(function(req, res, next) {
    console.log('GET ' + req.originalUrl)
    console.log('At %d', Date.now());
    next();
});

// Handle 404
app.use(function(req, res, next) {
    if(req.accepts('html') &amp;&amp; res.status(404)) {
        res.render('404.jade');
        return;
    }
});
</code></pre>
