-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (27 loc) · 802 Bytes
/
server.js
File metadata and controls
31 lines (27 loc) · 802 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
// Sync errors jo try catch mein nhi aaye
process.on("uncaughtException", (err) => {
console.log("UncaughtException! Shutting down..");
console.log(err.name, err.message);
process.exit(1);
});
require("dotenv").config();
const app = require("./src/app");
const connectDB = require("./src/config/db");
const PORT = process.env.PORT || 5000;
let server;
//connectDB
connectDB().then(() => {
server = app.listen(PORT, "0.0.0.0", () => {
console.log(`Server is running on ${PORT}`);
});
});
//handle Rejected promise -> Promise error jo catch nhi hue
process.on("unhandledRejection", (err) => {
console.log("UnhandledRejection! Shutting down!");
console.log(err.name, err.message);
if (server) {
server.close(() => {
process.exit(1);
});
} else process.exit(1);
});