forked from ayo-ola0710/Zero-Trust-System
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
29 lines (22 loc) · 771 Bytes
/
Copy pathserver.js
File metadata and controls
29 lines (22 loc) · 771 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
import { createServer } from "http";
import app from "./app.js";
import { config } from "./api/config/config.js";
import { initDb } from "./api/database/usersTable.js";
const server = createServer(app);
const startServer = async () => {
try {
console.log("Database connecting....");
// 1. Actually call the test function
await initDb();
console.log("✅ Database connected successfully!");
// 2. Start the server ONLY if DB connects
server.listen(config.port, () => {
console.log(`🚀 Server is running on port ${config.port}`);
});
} catch (error) {
console.error("❌ Database connection failed:", error.message);
process.exit(1); // Kill the server if DB is dead
}
};
// 3. Execute the function
startServer();