forked from Ubel-ITB/garuda_hacks-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
33 lines (29 loc) · 819 Bytes
/
app.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
require("dotenv").config();
const express = require("express");
const app = express();
const port = 4000;
const cors = require("cors");
const { MongoConnect } = require("./config/MongoConnect");
const router = require("./routes");
const { errorHandler } = require("./middlewares/Errorhandler");
const initialSeeding = require("./initialSeeding");
app.use(cors());
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(router);
app.use(errorHandler);
app.use((req, res) => {
res.status(404).json("NOT FOUND");
});
(async () => {
try {
await MongoConnect();
await initialSeeding();
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});
} catch (error) {
console.error("Failed to start app");
console.error(error);
}
})();