-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (26 loc) · 834 Bytes
/
Copy pathserver.js
File metadata and controls
31 lines (26 loc) · 834 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
const app = require("./index");
const db = require("./db/db");
const express = require("express");
const initDB = require("./db/init");
const protectedRoute = require("./routes/protectedRoutes");
const openRoute = require("./routes/openRoute")
//starting the server
const PORT = 4000;
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use("/api/v1", protectedRoute);
app.use("/", openRoute);
function start() {
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
}
//Initialising the database before starting the server
initDB().then(() => {
console.log("Database initialized successfully");
}).catch((error) => {
console.error("Error initializing database:", error);
}).finally(() => {
console.log("Starting the server...");
start();
});