forked from DugarRishab/Algo.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
56 lines (45 loc) · 1.49 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
46
47
48
49
50
51
52
53
54
55
const dotenv = require('dotenv');
const mongoose = require('mongoose');
dotenv.config({ path: './config.env' });
const app = require('./app');
// Below snippet is used to connect to DB. This is disablled becouse we will not be needing Database for this project
// Connecting to DATABASE ->>
// const DB = process.env.DATABASE.replace(
// '<PASSWORD>',
// process.env.DATABASE_PASSWORD
// );
// mongoose
// .connect(DB, {
// // <- Using Mongoose Connection
// useNewUrlParser: true,
// useCreateIndex: true,
// useFindAndModify: false,
// useUnifiedTopology: true,
// })
// .then(() => {
// console.log('DB connection established');
// })
// .catch((err) => {
// console.log('DB CONNECTION FAILED');
// console.log('ERR: ', err);
// });
// Catching uncaught exception ->>
process.on('unCaughtException', (err) => {
console.log(`UNCAUGHT EXCEPTION -> ${err.name} - ${err.message}`);
console.log('App SHUTTING DOWN...');
process.exit(1); // <- Then will shut down the server.
});
// Starting Server ->>
const port = process.env.PORT || 8000;
const server = app.listen(port, () => {
console.log(`App running at port`, (`${port}`), '...');
});
// Catching unHandleled Rejections ->
process.on('unhandledRejection', (err) => {
console.log(`UNHANDELLED REJECTION -> ${err.name} - ${err.message}`);
console.log(err);
console.log('App SHUTTING DOWN...');
server.close(() => { // <- This will first terminate all requests
process.exit(1); // <- Then will shut down the server.
});
});