How to access session in express, outside of the req?

后端 未结 4 1332
梦如初夏
梦如初夏 2021-02-04 01:14

I know that I can use

function(req, res) {
    req.session
}

using express. However I need to access the session outside of the response func

4条回答
  •  梦如初夏
    2021-02-04 02:08

    Assuming your socket.io code looks kinda like this:

    io.on('connection',
    function(client) {
      console.log(client.request)
    });
    

    The request is client.request as shown in the example above.

    Edit: As a separate thing, maybe this would help: https://github.com/aviddiviner/Socket.IO-sessions

提交回复
热议问题