-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (31 loc) · 921 Bytes
/
Copy pathindex.js
File metadata and controls
47 lines (31 loc) · 921 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
36
37
38
39
40
41
42
43
44
45
46
47
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
const port = process.env.PORT || 3000;
const http = require('http').Server(app);
const io = require("socket.io")(http);
app.use(bodyParser.json());
app.use(
bodyParser.urlencoded({
extended: true,
})
);
// routes
app.get("/", (request, response) => {
io.emit('connection');
response.json({ info: `Node.js, Express, and Postgres API ${port}` });
});
const allRoutes = require("./routes/index");
app.use("/api", allRoutes);
// socketIO events
io.on('connection', (socket) => {
socket.on('towerCreation', data => {
console.log("New record created!");
});
socket.on('towersUpdation', ()=> console.log("Record updated!"));
socket.on('towersDeletion', ()=> console.log("Record deleted!"));
});
// server
http.listen(port, () => {
console.log(`Server running on port ${port}.`);
});