node package manager

Share connect/express sessions with 1.x

Share connect/express sessions with 1.x


var socketSession = require("");
var session = {
    store: new connect.session.MemoryStore(),
    secret: "secret",
    key: "mykey.sid",
    cookieParser: connect.cookieParser("secret")
io.on("connection", function(socket){
    socket.on("whoAreYou", function(callback){
        //read from session 
    socket.on("setName", function(data) {
        //write to session =;


socket.emit("setName", { name: "hans" });
socket.emit("whoAreYou", function(name) { 
    console.log("I am " + name); 
//=> I am hans  

A full featured example can be found in the example folder.

Make sure to fire a http request to initialize the session/cookie before accessing the session with If you are serving the client with your node.js server this won't be a problem for you.