-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
35 lines (29 loc) · 801 Bytes
/
Copy pathapp.js
File metadata and controls
35 lines (29 loc) · 801 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
28
29
30
31
32
33
34
35
const express = require("express");
const http = require("http");
const app = express();
const path = require("path");
const server = http.createServer(app);
const socketIO = require("socket.io");
const moment = require("moment");
const io = socketIO(server);
app.use(express.static(path.join(__dirname, "src")));
const PORT = process.env.PORT || 3000;
server.listen(PORT, () => console.log(`server is running ${PORT}`));
io.on("connection", (socket) => {
socket.on("chatting", (data) => {
const { name, msg } = data;
io.emit("chatting", {
name,
msg,
time: moment(new Date()).format("h:mm A"),
});
});
});
io.on("connection", (socket) => {
socket.on("chatStart", (data) => {
const { name } = data;
io.emit("chatStart", {
name,
});
});
});