-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
35 lines (30 loc) · 1.4 KB
/
app.js
File metadata and controls
35 lines (30 loc) · 1.4 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
const app = require("express")(); // Initialize express app 🚀
const mongoose = require("mongoose"); // Import mongoose library ✅
const http = require("http").Server(app) // Import http
const config = require("./config/config"); // Import config module ⚙️
const router = require("./Routes/router"); // Import router module 🧭
const startCleanupSchedule = require('./utils/cleanup');
startCleanupSchedule.startCleanupSchedule();
const PORT = config.port; // Get port from config 🚪
const ConnectDB = async () => {
try {
await mongoose.connect(config.db).then(() => { // Connect to database 👍
console.log("Database connected ✨"); // Log success message 🎉
}).catch((error) => { // Handle connection errors ❌
setTimeout(ConnectDB, 20000); // Retry after 20 seconds ⏱️
console.warn("PP fail code: 1"); // Log error code ⚠️
});
} catch (error) { // Catch any other errors 🚨
console.log(error); // Log the error 😬
}
}
ConnectDB(); // Call connect function 🔗
app.use("/", router); // Use router middleware 🛣️
http.listen(PORT, () => { // Start the server 🚀
try {
console.log(`build sucessfully 🪓`); // Log success message 🎈
} catch (error) { // Catch any errors 💥
console.log(error); // Log the error 🤯
console.warn("PP fail code: 2"); // Log the fail code ❗
}
});