access express.js session from

npm install socket-io.sessions
1 downloads in the last day
9 downloads in the last week
39 downloads in the last month

Access Express session from

Build Status


npm install socket-io.sessions


  //configure passport and express

  var socketIo = require(""),
    socketIoSessions = require("socket-io.sessions");

  var sio = socketIo.listen(webServer);

  //same attribute than the session middleware

  sio.set("authorization", socketIoSessions({
    key:    'express.sid',       //the cookie where express (or connect) stores its session id.
    secret: 'my session secret', //the session secret to parse the cookie
    store:   mySessionStore      //the session store that express uses

  sio.sockets.on("connection", function(socket){

    socket.handshake.getSession(function (err, session) {
      socket.emit('aaa!', session.someSessionProperty);


Change the session

socket.handshake.getSession(function (err, session) {
  session.something = 123;
  socket.handshake.saveSession(session, function (err) {

Use with

  var sessionOptions = {
    key:    'express.sid',      
    secret: 'my session secret',
    store:   mySessionStore     
  //chain the two this way:
  sio.set("authorization", socketIoSessions(sessionOptions, passportSocketIo.authorize(sessionOptions)));


npm install npm test


MIT - José F. Romaniello 2012.

npm loves you