-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
36 lines (35 loc) · 902 Bytes
/
server.js
File metadata and controls
36 lines (35 loc) · 902 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
//This is the server
const app = require("./app");
const { connectToDb } = require("./models");
const config = require("./config/config");
const port = config.PORT || 5000;
const dBURl = config.DBCONNECTION_URL;
const server = app.listen(port, () => {
connectToDb(dBURl);
console.log(`server is listing at port ${port}`);
});
const handleExit = () => {
if (server) {
server.close(() => {
console.log("sever is shutting down");
process.exit(0);
});
} else {
process.exit(1);
}
};
const handleUnhandledError = (err) => {
if (config.ENV === "development") {
console.log(err);
handleExit();
}
handleExit();
};
process.on("uncaughtException", handleUnhandledError);
process.on("unhandledRejection", handleUnhandledError);
process.on("SIGTERM", () => {
console.log("SIGTERM");
if (server) {
server.close();
}
});