-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
26 lines (22 loc) · 656 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const express = require("express");
const { createServer } = require("node:http");
const path = require("path");
const { Server } = require("socket.io");
const app = express();
const server = createServer(app);
const io = new Server(server);
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "index.html"));
});
io.on("connection", (socket) => {
console.log("someone has been connected");
socket.on("chat message", (msg) => {
io.emit("chat message", msg);
});
socket.on("disconnect", () => {
console.log("disconnected");
});
});
server.listen(3000, () => {
console.log("server running at http:https://localhost:3000");
});