-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (30 loc) · 954 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
35
36
require('./models/db');
const appConfig = require('./config/appConfig');
const http = require('http');
const PORT = appConfig.PORT;
//catching uncaught exceptions
process.on('uncaughtException',(err)=>{
console.log("Uncaught Exception! Shutting down server...");
console.log(err.name,err.message);
process.exit(1);
})
const app = require('./app');
//server setup
const server = http.createServer(app);
server.listen(PORT, _ =>{
console.log(`Server running on PORT ${PORT}`)
});
// handling unhandled promises(safety net)
process.on('unhandledRejection',(err)=>{
console.log("Unhandled Rejection (Some Promise is unresolved)! Shutting down server...");
console.log(err.name,err.message);
server.close(()=>{
process.exit(1);
})
});
process.on('SIGTERM',()=>{
console.log("SIGTERM Received. Shutting down server gracefully...");
server.close(()=>{
console.log('Process Terminated...');
})
})