forked from codewithshahnawaz/book-directory-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
40 lines (35 loc) · 1022 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
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const bookRoute = require("./routes/bookRoutes");
const userRoute = require("./routes/userRoutes");
const cookieParser = require("cookie-parser");
const session = require("express-session");
app.use(cookieParser());
app.use(
session({
secret: "its secret shaan!",
resave: true,
maxAge: 24 * 60 * 60,
saveUninitialized: false,
})
);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use("/api/book", bookRoute);
app.use("/api/user", userRoute);
app.get("/api/", function (req, res, next) {
res.send("<h1>Home page: api</h1>");
next();
});
const PORT = process.env.PORT || 4000;
app.listen(PORT, () => {
console.log("listening on http://localhost:" + PORT);
mongoose
.connect(
"mongodb+srv://shaan:[email protected]/?retryWrites=true&w=majority"
)
.then(() => {
console.log("Mongodb is connected");
});
});