socketHandler
function socketHandler(app: Object, config: Object = {})
Initializes a Socket.IO server with an HTTP server.
Returns: Object
- Configured Socket.IO server instance.
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
app | Object | Express application instance. | ||
config | Object | ✔️ | Socket.IO server configuration options. See the official socket.io package documentation for more details: |
See:
const express = require("express");
const app = express();
const io = socketHandler(app, { cors: { origin: "*" } });
io.on("connection", (socket) => {
console.log("A user connected");
});