express-socket.io-router
v1.0.5
Published
Express-like routing interface for Socket.IO
Downloads
12
Readme
express-socket.io-router
Express-like routing interface for Socket.IO
Install
npm install --save express-socket.io-router
Usage
Server
const SocketIO = require('socket.io');
const ExpressSocketIO = require('express-socket.io-router');
var io = new SocketIO(8080);
ExpressSocketIO(io);
io.register('test:path', function(req, res, next){
console.log('request:', req.query, req.socket);
res.send({
query: req.query
});
next();
});
Client
const SocketIOClient = require('socket.io-client');
client = SocketIOClient.connect('http://localhost:8080');
client.emit('test:path', { data: 'test' }, function(err, res){
console.log('response:', res);
});