forked from muhammadsemeer/Gentex-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (35 loc) · 967 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require("dotenv").config();
const http = require("http");
const app = require("./app");
const connectDB = require("./utils/db");
// Create HTTP server
const server = http.createServer(app);
// Setting PORT
const PORT = process.env.PORT || 3001;
app.set("port", PORT);
server.listen(PORT);
connectDB();
const onListen = () => {
console.log(`Server running on ${PORT} in ${process.env.NODE_ENV} mode`);
};
const onError = (error) => {
console.log("Sever Error");
console.log(error.message);
// eslint-disable-next-line no-process-exit
process.exit(1);
};
server.on("listening", onListen);
server.on("error", onError);
// Exception Handler
process
.on("uncaughtException", (err) => {
console.error("Uncaught Exception: ", err);
})
.on("unhandledRejection", (reason, p) => {
console.error(
"Unhandled Rejection at: Promise ",
p,
" reason: ",
reason
);
});