-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
51 lines (41 loc) · 1.52 KB
/
server.js
File metadata and controls
51 lines (41 loc) · 1.52 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
51
const dotenv = require("dotenv");
const dotenvExpand = require("dotenv-expand");
// Load and expand environment variables
const myEnv = dotenv.config();
dotenvExpand.expand(myEnv);
require("module-alias/register");
const mongoose = require("mongoose");
const { app } = require("@app");
const { DB_URL } = require("@configs/db.config");
const { PORT_NUMBER } = require("@configs/server.config");
const { logWithTime } = require("@utils/time-stamps.util");
const { errorMessage } = require("@/responses/common/error-handler.response");
(async () => {
try {
// 🔑 DATABASE CONNECTION (CORRECT WAY)
await mongoose.connect(DB_URL);
logWithTime("✅ Connection established with MongoDB Successfully");
// 🔄 Microservice Init
try {
const {
initializeMicroservice,
setupTokenRotationScheduler
} = require("@services/bootstrap/microservice-init.service");
await initializeMicroservice();
setupTokenRotationScheduler();
} catch (err) {
logWithTime("⚠️ Microservice init failed");
errorMessage(err);
}
// 🚀 Start Server
app.listen(PORT_NUMBER, () => {
logWithTime(`🚀 Server running on port ${PORT_NUMBER}`);
require("@cron-jobs");
logWithTime("✅ Cron Jobs Initialized");
});
} catch (err) {
logWithTime("❌ MongoDB Connection Failed");
errorMessage(err);
process.exit(1);
}
})();