-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathserver.js
More file actions
49 lines (40 loc) · 1.37 KB
/
server.js
File metadata and controls
49 lines (40 loc) · 1.37 KB
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
46
47
48
49
const mongoose = require('mongoose');
const dotenv = require('dotenv').config();
const app = require('./index.js');
const port = process.env.PORT || 3000;
const DB = process.env.DATABASE.replace(
'<PASSWORD>',
process.env.DATABASE_PASSWORD
);
console.log('✅ Application started');
console.log(`✅ Running ${process.env.NODE_ENV} server`);
mongoose
.connect(DB, {
useNewUrlParser: true, // After mongoose version 5.7.1 release
useUnifiedTopology: true
})
// .then((con) => {//for seeing more info
.then(() => {
// console.log(con.connection);//to see more info about the connection
console.log('✅ MongoDB connected successfully 👍🎉');
});
// app.listen(port, () => {
// console.log(`Server started on http://localhost:${port}`);
// });
const server = app.listen(port, () => {
console.log(`✅ Server started on http://localhost:${port} 👈`);
});
process.on('unhandledRejection', err => {
console.log(err.name, err.message);
console.log('Unhandled Error Detected! 💥 Closing down the application...');
server.close(() => {
process.exit(1);
})
});
//When Heroku recieves SIGTERM call it terminates all the ongoing requests and we don't want that so
process.on('SIGTERM', () => {
console.log('SIGTERM recieved. Shutting down the server 👋');
server.close(() => {
console.log('💥 Process terminated');
})
});