I usually use the cluster module to scale a normal express server, and I want to do the same with socket.io. I found out I can use the socket.io-redis library, but there was no example on how to use it with the cluster module. I already looked at this question: Scaling Socket.IO to multiple Node.js processes using cluster, but socket.io servers were created differently than my current implementation.
Here is my code:
const express = require("express");
const app = express();
const origin = "http://localhost:3000";
const io = require("socket.io")(3001, {
cors: {
origin: [origin]
}
});
io.on("connection", function (socket) {
// Code here...
});
app.listen(3000);