-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
33 lines (25 loc) · 793 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
const app = require('./app')
const connectDatabase = require('./config/database')
// Config
if (process.env.NODE_ENV !== "PRODUCTION") {
require("dotenv").config({ path: "config/config.env"});
}
//UnCaught Excception
process.on('uncaughtException', (err) => {
console.log(`Error: ${err.message}`)
console.log(`Shutting down server due to Uncaught Exception`)
process.exit(1)
})
//connection database
connectDatabase();
const server = app.listen(8080, () => {
console.log(`Server is running on port 8080`)
})
//Unhandled Promise Rejection
process.on('unHandledException', error => {
console.log(`Error: ${error.message}`)
console.log(`Shutting down the server due to unhandled promise rejection`)
server.close(() => {
process.exit(1);
});
});