-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
28 lines (24 loc) · 807 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
const app = require('./app')
const dotenv = require("dotenv")
const connectToDB = require("./config/database")
//handling uncaught exception
dotenv.config({ path: "server/config/config.env" })
process.on("uncaughtException",(err)=>{
console.log(`error:${err.message}`)
console.log('Shutting down the server because of uncaught exception');
process.exit(1)
})
connectToDB()
const server = app.listen(process.env.PORT, () => {
console.log(`server is working on port http://localhost:${process.env.PORT}`)
})
console.log()
//If mongodb url is wrong
process.on("unhandledRejection", (err) => {
console.log(`error:${err.message}`)
console.log("Shutting down the server due to unhandled rejection")
server.close(() => {
process.exit(1)
})
})
//Code bro don't waste time