express-rest-api-boilerplate icon indicating copy to clipboard operation
express-rest-api-boilerplate copied to clipboard

Adding Socket Listener on same port.

Open prabhatbharat opened this issue 3 years ago • 0 comments

Hi,

I was wondering to add socket.io on the same port, something like this.

const app = require('./index.js');
const port = process.env.PORT;

// Server
let server = app.listen(port, () => {
  console.log(`Listening TCP on: http://localhost:${port}`);
});

let io     = require('socket.io')(server);
console.log(` WS on: http://localhost:${port}`);
io.on('connection', (socket) => {
  console.log('IO user connected');
});

I need some ideas to create routes for socket IO. I am not able to figure out that routing mechanism.

prabhatbharat avatar May 04 '21 13:05 prabhatbharat