-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
45 lines (41 loc) · 1.08 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
34
35
36
37
38
39
40
41
42
43
44
45
const mongoose = require('mongoose');
require('dotenv').config();
const app = require('./app');
const run = async () => {
await mongoose.connect(process.env.DATABASE_URI, {
dbName: 'Natours',
});
};
const PORT = process.env.PORT || 7000;
run()
.then((_con) => {
console.log('db connected');
const server = app.listen(PORT, () =>
console.log(`App Running on http://localhost:${PORT}`)
);
process.on('uncaughtException', (err) => {
console.log('uncaught Exeception! 💥 Shuttig Down!');
console.log(err);
server.close(() => {
process.exit(1);
});
});
process.on('unhandledRejection', (err) => {
console.log('Unhandled Rejection! 💥 Shuttig Down!');
console.log(err);
server.close(() => {
process.exit(1);
});
});
process.on('SIGTERM', () => {
console.log('SIGTERM Recieved! 💥 Shuttig Down!');
server.close(() => {
process.exit(1);
});
});
})
.catch((error) => {
console.log(error.message);
process.exit();
});
// process.on('uncaughtException');