forked from extwiii/Nodejs-Real-time-Chat-App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
27 lines (24 loc) · 793 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
27
var express = require("express");
var app = express();
var port = process.env.PORT || 3700;
// Set view of '/' end point
app.set("views", __dirname + "/views");
app.set("view engine", "jade");
app.engine("jade", require("jade").__express);
app.get("/", function (req, res) {
res.render("page");
});
// use our puclic/chat.js file as listener
app.use(express.static(__dirname + "/public"));
// Set port
var midPort = app.listen(port, function () {
console.log("Node.js listening on port " + port);
});
var io = require("socket.io").listen(midPort);
// set up socket connection
io.sockets.on("connection", function (socket) {
socket.emit("message", { message: "Welcome to the Real Time Web Chat" });
socket.on("send", function (data) {
io.sockets.emit("message", data);
});
});