-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
41 lines (32 loc) · 986 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 port = process.env.PORT;
const authRoutes = require("./routes/auth");
const userRoutes = require("./routes/user");
const noteRoutes = require("./routes/notes");
const app = express();
const cookieParser = require("cookie-parser");
const bodyParser = require("body-parser");
var cors = require("cors");
const mongoose = require("mongoose");
require("dotenv").config();
const link = process.env.DATABASE;
const db = mongoose.connection;
//Db connection
mongoose.connect(link, {
dbName: "notes-app",
});
db.on("error", console.error.bind(console, "MongoDB connection error:"));
db.once("open", () => {
console.log("Connected to MongoDB");
});
//Common Middlewares
app.use(cookieParser());
app.use(bodyParser.json());
app.use(cors());
app.use(bodyParser.urlencoded({ extended: true }));
app.use("/api", authRoutes);
app.use("/api", userRoutes);
app.use("/api", noteRoutes);
app.listen(port, () => {
console.log("db is running");
});