What's difference with express-session and cookie-session?

后端 未结 7 1376
既然无缘
既然无缘 2021-01-30 00:00

I am new with Express. As Express 4.x has removed bundled middlewares. Any middleware I want to use should be required. When I read the README with exp

7条回答
  •  甜味超标
    2021-01-30 00:40

    The get a non-empty console.log(req.session) you need to set session values before logging.

    From the cookie-session repo (https://github.com/expressjs/cookie-session):

    app.get('/', function (req, res, next) {
     req.session.views = (req.session.views || 0) + 1
     console.log(req.session)
     res.end(req.session.views + ' views')
    })
    

    If you never set any info on the req.session object, it will return empty.

提交回复
热议问题