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
});
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'];
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With