-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (32 loc) · 863 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
38
39
40
41
const express = require("express");
const mongoose = require("mongoose");
const cors = require("cors");
require("dotenv").config();
// setting options for CORS
var corsOptions = {
origin: ["http://localhost:3000"],
methods: "GET,PUT,PATCH,POST,DELETE"
}
const bodyparser = require("body-parser");
// api route
const api = require("./routes/api");
const app = express();
app.use(bodyparser.json());
app.use(cors(corsOptions));
const uri = process.env.MONGODB_URI;
//Connect to monodb atlas
mongoose
.connect(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log("connected to DB......");
})
.catch((err) => console.log(err));
mongoose.set("debug", true);
const PORT = process.env.PORT || 8000;
app.listen(PORT, () => {
console.log(`server is running on port ${PORT}`);
});
app.use("/api", api);