Tag Archives: cookies

How to access cookie data inside a socket.io connection?

I am using node.js and socket.io. on the client side, I wrote a cookie like this:

var socket = io.connect('http://localhost:3000');
document.cookie="foo=bar";
socket.emit('this', { is: 'test'});

and on the server side, I need to be able to read from that cookie inside a socket.io connection, something like this:

io.sockets.on('connection', function (socket) {
    socket.on('this', function(reqData){ 
        console.log(socket.handshake.headers); // there is no cookies here!
    });
}

a no-framework solution is preferred, any help is appreciated. thanks.

update: in this gist you can find my complete code.