how to get request path with express req object

I’m using express + node.js and I have a req object, the request in the browser is /account but when I log req.path I get “https://stackoverflow.com/” — not ‘/account’.

  //auth required or redirect
  app.use('/account', function(req, res, next) {
    console.log(req.path);
    if ( !req.session.user ) {
      res.redirect('/login?ref="+req.path);
    } else {
      next();
    }
  });

req.path is / when it should be /account ??

10 Answers
10

Leave a Comment