sachin sachin - 6 months ago 28
Node.js Question

In Socket.io, how to get the stored cookie information?

In node application using express, I have stored cookie information. Now I need to get the stored cookie information in socket.io. How can I get this?

app.use(function (req, res, next) {

res.cookie('cookieName','1', { maxAge: 50000, httpOnly: true });
});

io.sockets.on('connection', function (socket) {

//here i need to access the cookie.how can i do this

});

Answer

Finally i found the answer.The below code will get the cookie information.

     io.sockets.on('connection', function (socket) {

          var cookie=socket.handshake.headers['cookie'];

     });