Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

socket.io-express-session

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

socket.io-express-session

Use express-session as socket.io middleware.

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

socket.io-express-session

Use express-session as socket.io middleware.

Setup

All you have to is adding a middleware like you would in your express app.

var ios = require('socket.io-express-session');
var session = ... configured express-session instance
...

io.use(ios(session));
...
io.on('connection', function(socket){
  console.log(socket.handshake.session);
});

Example

// initializing express-session middleware
var Session = require('express-session'),
    SessionStore = require('session-file-store')(Session);
var session = Session({ secret: 'pass', resave: true, saveUninitialized: true });

// creating new express app
var express = require('express');
var app = express();
app.use(session); // session support
app.get('/', function (req, res) {
  req.session.uid = 1;
  res.send('Hi user #' + req.session.uid);
});

// attaching express app to HTTP server
var http = require('http');
var server = http.createServer(app);
server.listen(process.env.PORT || '3000');

// creating new socket.io app
var ios = require('socket.io-express-session');
var io = require('socket.io')(server);
io.use(ios(session)); // session support
io.on('connection', function(socket){
  console.log(socket.handshake.session);
});

Keywords

FAQs

Package last updated on 04 Apr 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc