-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (24 loc) · 690 Bytes
/
Copy pathindex.js
File metadata and controls
29 lines (24 loc) · 690 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
var express = require("express");
var socket = require("socket.io");
const path = require("path");
var app = express();
var server = app.listen(4000, function() {
console.log("listening to request on port 4000");
});
if (process.env.NODE_ENV === "production") {
// set static folder
app.use(express.static("build"));
app.get("*", (req, res) => {
res.sendfile(path.resolve(__dirname, "build", "index.html"));
});
}
// socket setup
var io = socket(server);
io.on("connection", function(socket) {
socket.on("connection", function() {
io.sockets.emit("chat", "Hello there");
});
socket.on("chat", function() {
io.sockets.emit("chat", "Just chating");
});
});