-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (26 loc) · 929 Bytes
/
server.js
File metadata and controls
32 lines (26 loc) · 929 Bytes
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
const app = require("./app.js");
require("@dotenvx/dotenvx").config();
const mongoose = require("mongoose");
const port = process.env.PORT || 8000;
const dbUrl = process.env.DB_URL.replace("<USER>", process.env.DB_USER).replace(
"<PASSWORD>",
encodeURIComponent(process.env.DB_PASSWORD)
);
mongoose
.connect(dbUrl)
.then(() => console.log("Database Connected Successfully!"))
.catch((err) => console.error("MongoDB Connection Error:", err));
const server = app.listen(port, () => {
console.log(`Server running on Port ${port}`);
});
process.on("uncaughtException", (err) => {
console.log("UncaughtException Error", err);
console.log("UncaughtException Error server Shutting Down......");
server.close(() => {
process.exit(1);
});
});
process.on("unhandledRejection", (err) => {
console.log("unhandledRejection Error", err);
console.log("unhandledRejection Error Server Shutting Down.....");
});