How to pass socket.io to express routes in files?

Socket.io is a popular library used to enable live (real-time) communication across server and client(s). It uses events to receive to transmit data. We’ll be discussing how to use it with Express route files. We’ll be dealing with the new 3.x version of the socket.io, which is a bit different. You can have a look at this migration guide from 2.x to 3.0. Basically, we create a simple middleware: const { createServer } = require("http"); // you can use https as well const express = require("express"); const socketIo = require("socket....

February 13, 2021 · 2 min