-
Notifications
You must be signed in to change notification settings - Fork 10
/
app.js
37 lines (34 loc) · 936 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
34
35
36
37
const express = require("express");
require("express-async-errors");
const app = express();
require("dotenv").config();
const cors = require("cors");
const router = require("./routes/routes");
const mongoose = require("mongoose");
const Team = require("./models/Teams");
const PORT = process.env.PORT || 8000;
app.use(cors({ origin: true }));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
mongoose.set("strictQuery", true);
app.use("/api", router);
app.get("/", async (req, res) => {
res.send("prastuti");
});
mongoose.connect(process.env.MONGO_URI).then(() => {});
const start = async () => {
await mongoose
.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
app.listen(PORT, () => {
console.log(`Listening on port ${PORT}`);
});
})
.catch((error) => {
console.log(error);
});
};
start();