-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
35 lines (29 loc) · 971 Bytes
/
server.js
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 express = require("express");
const chalk = require("chalk");
const dotenv = require("dotenv");
const bodyParser = require("body-parser");
const cors = require("cors");
const http = require("http");
const { syncUserModel, syncAdminModel } = require("./util/syncModels");
const { connectDB, closeDB } = require("./util/dbCheck");
const routes = require("./routes/routes");
dotenv.config();
const app = express();
const server = http.createServer(app);
app.use(bodyParser.json({ limit: "100MB" }));
app.use(cors({ credentials: true, origin: true }));
const startServer = async () => {
try {
await connectDB();
server.listen(process.env.PORT, () => {
console.log(chalk.black.bgGreen("Server Started ! "));
});
await syncUserModel();
await syncAdminModel();
app.use("/", routes);
} catch (e) {
console.log(chalk.bgRed("Error : ", e));
}
// await closeDB();
};
startServer();