-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·36 lines (36 loc) · 1.02 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
const mongoose = require('mongoose');
const dotenv = require('dotenv');
process.on('uncaughtException', (err) => {
console.error(`${err.name} and ${err.message}`);
// console.log(err);
console.log('Uncaught Exception : Shutting Down');
process.exit(1);
});
dotenv.config({
path: './config.env',
});
const app = require('./app');
const DB = process.env.DATABASE.replace('<PASSWORD>', process.env.PASSWORD);
mongoose
// .connect('mongodb://localhost:27017/Natours-App', {
.connect(DB, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log('Database connected Successfully');
})
.catch((error) => {
console.error('Error connecting to database:', error);
});
const PORT = process.env.PORT || 3001;
const server = app.listen(PORT, () => {
console.log(`App Running on port ${PORT}`);
});
process.on('unhandledRejection', (err) => {
console.error(err.name + ' ' + err.message);
console.log('Unhandled Rejection : Shutting Down');
server.close(() => {
process.exit(1);
});
});