{"library":"socket.io-express-session","title":"Socket.IO Express Session Middleware","type":"library","description":"This package, `socket.io-express-session`, provides middleware to integrate and share `express-session` instances with `socket.io`. It allows developers to access the same session object (`socket.handshake.session`) within Socket.IO connection handlers that they would normally access via `req.session` in an Express application. The package is extremely old, with its latest version (0.1.3) published over 10 years ago in September 2015. Due to its age, it is considered abandoned and does not support modern JavaScript module systems (ESM) or recent versions of `express-session` and `socket.io` without potential compatibility issues. Modern applications typically integrate `express-session` with `socket.io` directly by using the `sessionMiddleware` within `io.engine.use()` or `io.use()` with a custom wrapper, as shown in current Socket.IO documentation.","language":"javascript","status":"abandoned","last_verified":"Thu Apr 23","install":{"commands":["npm install socket.io-express-session"],"cli":null},"imports":["const ios = require('socket.io-express-session');","const connectSession = require('socket.io-express-session');","/// <reference types=\"node\" />\n// No official TypeScript types exist, manual declaration or @types/module-name might be needed for older packages."],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/xpepermint/socket.io-express-session","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/socket.io-express-session","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"const express = require('express');\nconst { createServer } = require('http');\nconst session = require('express-session');\nconst { Server } = require('socket.io');\nconst ioSession = require('socket.io-express-session'); // The package being documented\n\nconst app = express();\nconst httpServer = createServer(app);\nconst io = new Server(httpServer);\n\n// IMPORTANT: Use a production-ready session store, not MemoryStore for production.\nconst sessionMiddleware = session({\n  secret: 'my-super-secret-key-that-should-be-long-and-random',\n  resave: false,\n  saveUninitialized: true,\n  // store: new (require('connect-redis')(session))({ client: require('redis').createClient() })\n});\n\napp.use(sessionMiddleware);\n\n// Integrate express-session with Socket.IO\nio.use(ioSession(sessionMiddleware));\n\nio.on('connection', (socket) => {\n  console.log('A user connected:', socket.id);\n  // Access the session from the handshake object\n  const userSession = socket.handshake.session;\n  if (userSession) {\n    console.log('Session data on connection:', userSession);\n    userSession.views = (userSession.views || 0) + 1;\n    console.log('Updated views:', userSession.views);\n    // In older packages, you might need to manually save if 'autoSave' isn't configured/available.\n    // userSession.save(); // Not explicitly mentioned as needed by this package\n  }\n\n  socket.on('disconnect', () => {\n    console.log('User disconnected:', socket.id);\n  });\n});\n\napp.get('/', (req, res) => {\n  req.session.pageViews = (req.session.pageViews || 0) + 1;\n  res.send(`Hello from Express! Page views: ${req.session.pageViews}`);\n});\n\nconst PORT = process.env.PORT || 3000;\nhttpServer.listen(PORT, () => {\n  console.log(`Server running on http://localhost:${PORT}`);\n});","lang":"javascript","description":"This quickstart demonstrates how to set up `socket.io-express-session` to share Express sessions with Socket.IO connections, allowing access to `socket.handshake.session`. It includes basic Express and Socket.IO server initialization and highlights session access within Socket.IO connection handlers.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}