-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
33 lines (29 loc) · 876 Bytes
/
Copy pathserver.js
File metadata and controls
33 lines (29 loc) · 876 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
//Uncaught exception -> Basicaly sync errors that are not catched using try catch block
process.on("uncaughtException", (err) => {
console.log("uncaughtException shutting down...");
console.log(err.name, err.message);
process.exit(1);
});
//Require dotenv
require("dotenv").config();
const app = require("./src/app");
const connectDB = require("./src/config/db");
//Port
const PORT = process.env.PORT || 5000;
//connect db
let server;
connectDB().then(() => {
server = app.listen(PORT, "0.0.0.0", () => {
console.log(`Server is running on ${PORT}`);
});
});
//unhandled rejection ->promise errors that are not catched
process.on("unhandledRejection", (err) => {
console.log("unhandled rejection shutting down ...");
console.log(err.name, err.message);
if (server) {
server.close(() => {
process.exit(1);
});
} else process.exit(1);
});