-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
27 lines (24 loc) · 717 Bytes
/
Copy pathserver.js
File metadata and controls
27 lines (24 loc) · 717 Bytes
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
27
const express = require("express");
const app = express();
const path = require("path");
const http = require("http").Server(app);
const io = require("socket.io")(http);
//SERVER THE PUBLIC DIRECTORY
http.listen("3000", () => {
console.log("listening at port 3000");
});
io.on("connection", (socket) => {
console.log("user connected");
socket.on("disconnect", () => {
console.log("user disconnected");
});
socket.on("message", (message) => {
console.log(message);
//BROADCASTING MESSAGE TO EVERYONE
io.emit("message", message);
});
});
app.use(express.static(path.join(__dirname, "public")));
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, +"public/index.html"));
});