-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
33 lines (29 loc) · 1.09 KB
/
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 mongoose = require('mongoose');
const dotenv = require('dotenv').config({ path: './config.env' });
const colors = require('colors');
const DBConnect = require('./utils/dbConnect');
process.on('uncaughtException', (error) => {
// using uncaughtException event
console.log(' uncaught Exception => shutting down..... ');
console.log(error.name, error.message);
process.exit(1); // emidiatly exists all from all the requests
});
const app = require('./app');
// database connection
DBConnect();
// server
const port = process.env.PORT || 7000;
const server = app.listen(port, () => {
console.log(`App is running on port ${port}`.yellow.bold);
});
// handle Globaly the unhandle Rejection Error which is outside the express
// e.g database connection
process.on('unhandledRejection', (error) => {
// it uses unhandledRejection event
// using unhandledRejection event
console.log(' Unhandled Rejection => shutting down..... ');
console.log(error.name, error.message);
server.close(() => {
process.exit(1); // emidiatly exists all from all the requests sending OR pending
});
});