-
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) · 754 Bytes
/
Copy pathindex.js
File metadata and controls
29 lines (24 loc) · 754 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 app = express();
var http = require("http").createServer(app);
var io = require("socket.io")(http);
var port = process.env.PORT || 3700;
// Set view of '/' end point
app.set("views", __dirname + "/views");
app.set("view engine", "pug");
app.get("/", function (req, res) {
res.render("page");
});
// Use our public/chat.js file as listener
app.use(express.static(__dirname + "/public"));
// Set port
http.listen(port, function () {
console.log("Node.js listening on port " + port);
});
// Set up socket connection
io.on("connection", function (socket) {
socket.emit("message", { message: "Welcome to the Real Time Web Chat" });
socket.on("send", function (data) {
io.emit("message", data);
});
});