Handling 404 pages with express and node.js

abemassry        
1 Likes   0 Comments  javascript

app.get('/404', function(req, res){
    
    if (req.user) {
      var username = req.user.username; 
    }
    
    res.render('404.jade', {
        locals: {
          page: 'Not Found',
          user: username
        }
    });
  });
  
  //last function before end of file
  app.use(function(req,res){
    res.redirect('/404');
  });
created with codestagram