-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
50 lines (45 loc) · 1.19 KB
/
server.js
File metadata and controls
50 lines (45 loc) · 1.19 KB
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
48
49
50
const http = require("http");
const app = require("./config/express");
const connectDB = require("./config/mongoose");
require("dotenv").config();
const port = process.env.PORT;
//Socket.io---------------------------------
const socket = require("./socket");
//Socket.io---------------------------------
// Create Http Server
const server = http.createServer(app);
server.listen(port || 3000);
// Listening on listening to port
const onListening = () => {
connectDB();
console.log(`Server is Running on port ${port} `);
};
// Listen to error on listening to port
const onError = (error) => {
if (error.syscall !== "listen") {
throw error;
}
const bind = typeof port === "string" ? `Pipe ${port}` : `Port ${port}`;
switch (error.code) {
case "EACCES":
console.log(`${bind} requires elevated privileges`);
process.exit(1);
break;
case "EADDRINUSE":
console.log(`${bind} is already in use`);
process.exit(1);
break;
default:
console.log(`Error not know`);
process.exit(1);
throw error;
}
};
/**
* Exports Express
* @public
*/
server.on("listening", onListening);
server.on("error", onError);
socket(server);
module.exports = server;