app.use(function(req, res, next) { if (req.user == null && req.path.indexOf('/admin') === 0) { res.redirect('/login'); } next(); });