-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
32 lines (26 loc) · 804 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
const app = require('./app/app');
const PORT = process.env.PORT || 3000;
let server;
const startServer = () => {
return app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
};
const handleUnhandledRejection = (reason, promise) => {
console.log(`Unhandled Rejection at => Promise: ${promise} - reason: ${reason}`);
restartServer();
};
const handleUncaughtRejection = (err) => {
console.log(`Uncaught Exception: ${err}`);
restartServer();
};
const restartServer = () => {
server.close(() => {
server = startServer();
console.log(`Server is restarted on port ${PORT}`);
});
};
process
.on('unhandledRejection', handleUnhandledRejection)
.on('uncaughtException', handleUncaughtRejection);
server = startServer();