-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
51 lines (42 loc) · 1.2 KB
/
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
42
43
44
45
46
47
48
49
50
51
const express = require("express");
const mongoose = require("mongoose");
const app = express();
const dotenv = require("dotenv");
const cors = require("cors");
const notesRouter = require("./routes/notesRoutes");
const userRoutes = require("./routes/userRoutes");
const corsOptions = {
origin: "https://your-notes-chi.vercel.app",
// origin: "http://localhost:3000",
credentials: true, //access-control-allow-credentials:true
optionSuccessStatus: 200,
};
app.use(cors(corsOptions));
app.use(express.json());
dotenv.config({ path: "./config.env" });
const DB = process.env.DATABASE.replace(
"<PASSWORD>",
process.env.DATABASE_PASSWORD
);
mongoose
.connect(DB, {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true,
})
.then((con) => {
console.log(con.connections);
console.log("Db connection succesfull ✌");
})
.catch((err) => {
console.log("ERROR :", err);
});
// app.get("/", (req, res) => {
// res.status(200).send("hello from the server✌✌");
// });
app.use("/", notesRouter, userRoutes);
const port = process.env.PORT || 8000;
app.listen(port, () => {
console.log(`app is running on port ${port}...`);
});