-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
50 lines (42 loc) · 1.28 KB
/
server.js
File metadata and controls
50 lines (42 loc) · 1.28 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
50
require("dotenv").config();
const mongoose = require("mongoose")
const app = require("./app");
// Connecting to DATABASE ->>
const DB = process.env.MONGO_CLIENT_URI.replace(
'<db_password>',
process.env.MONGO_CLIENT_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 cCONNECTION ERROR: " + err.message);
});
// 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.
});
// 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.
});
});
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});