Skip to content

Commit b807869

Browse files
committed
init
1 parent 8b29dd1 commit b807869

14 files changed

+10989
-0
lines changed

home.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//load modules
2+
var express = require("express");
3+
var app = express();
4+
const http = require("http");
5+
const server = http.createServer(app);
6+
const { Server } = require("socket.io");
7+
const io = new Server(server);
8+
var bodyParser = require("body-parser");
9+
const port = process.env.PORT || 3002;
10+
11+
//set view engine to ejs
12+
app.set("view engine", "ejs");
13+
14+
//set upp public directory to serve static files
15+
app.use(express.static("public"));
16+
17+
//Initiate bodyParser to parse request body
18+
app.use(
19+
bodyParser.urlencoded({
20+
extended: true,
21+
})
22+
);
23+
app.use(bodyParser.json());
24+
25+
//Routes
26+
27+
app.get("/", (req, res) => {
28+
res.render("index");
29+
});
30+
31+
// Socket.io
32+
io.on("connection", (socket) => {
33+
console.log("a user connected");
34+
socket.on("disconnect", () => {
35+
console.log("user disconnected");
36+
});
37+
});
38+
39+
// Run server
40+
server.listen(port, () => {
41+
console.log("listening on *:" + port);
42+
console.log("http://localhost:" + port);
43+
});

0 commit comments

Comments
 (0)