Skip to content

Should the access modifier of the httpServer object be set to private? #4794

Answered by darrachequesne
zicjin asked this question in Q&A
Discussion options

You must be logged in to vote

Hi! I think you should provide your own HTTP server:

import { createServer } from "node:http";
import { Server } from "socket.io";

const httpServer = createServer();
const io = new Server(httpServer, { /* options */ });

io.on("connection", (socket) => {
  // ...
});

httpServer.on("error", () => {
  // ...
});

httpServer.listen(3000);

Reference: https://socket.io/docs/v4/server-initialization/#with-an-http-server

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by darrachequesne
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants