Home > database >  Socket.io Standalone vs sockets inside an express router
Socket.io Standalone vs sockets inside an express router

Time:10-12

I'm new to sockets and I'm trying to figure out the pros and cons of these two implementations.

Why emit events using socket.io inside an express route handler then just using a socket.io listener and emit events through it without an express route?

CodePudding user response:

The main difference is that using socket.io inside an express route handler gives you more control over the data that is being emitted. For example, you can easily add middleware to an express route handler to validate data before emitting it.

Another difference is that using a socket.io listener gives you more flexibility in terms of where you can put your code. For example, you could put your socket.io listener inside a separate module and then require it in your express route handler.

  • Related