-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
34 lines (25 loc) · 868 Bytes
/
server.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
const app = require("./app");
const dotenv = require("dotenv");
const connectDatabase = require("./config/Db")
// Handling uncaught exception
process.on("uncaughtException", (err) => {
console.log(`Error : ${err.message}`);
console.log(`Shutting down the server due to uncaught exception error`);
process.exit(1)
})
// console.log(youtube)
//config
dotenv.config({ path: "backend/config/Config.env" })
// after config we are calling database
connectDatabase();
const server = app.listen(process.env.PORT, () => {
console.log(`Server is working on http://localhost:${process.env.PORT}`)
})
// unhandled promise rejection [ERROR HANDLING]
process.on("unhandledRejection", (err) => {
console.log(`Error: ${err.message}`);
console.log(`Shutting down the server due to unhandled Promise Rejection`);
server.close(() => {
process.exit(1);
})
})