-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (40 loc) · 1.04 KB
/
server.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const app = require("./app");
const dotenv = require("dotenv");
const mongoose = require("mongoose");
// const socket = require("socket.io");
// Env config:
dotenv.config({ path: "./config.env" });
// Connect to DB:
const DB = process.env.DB.replace("<PASSWORD>", process.env.DB_PASSWORD);
mongoose
.connect(DB, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log("DB connection successful");
})
.catch((err) => {
console.log(err);
});
// Server:
const PORT = process.env.PORT || 3000;
const server = app
.listen(PORT, () => {
console.log(
`Server is running on port ${PORT} in ${process.env.NODE_ENV} mode on http://localhost:${PORT}`
);
})
.on("error", (err) => {
console.log(err);
});
// const io = socket(server);
// let onlineUsers = 0;
// io.on("connection", (socket) => {
// onlineUsers++;
// io.emit("user-count-change", onlineUsers);
// socket.on("disconnect", () => {
// onlineUsers--;
// io.emit("user-count-change", onlineUsers);
// });
// });