-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
43 lines (33 loc) · 995 Bytes
/
server.js
File metadata and controls
43 lines (33 loc) · 995 Bytes
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
const express = require('express');
const dotenv = require('dotenv');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const jwt = require('jsonwebtoken');
const bookRoutes = require("./routes/books");
const categoryRoutes = require("./routes/categories");
const app = express();
dotenv.config();
const PORT = process.env.PORT || 8000
app.use("/api/books", bookRoutes);
app.use("/api/categories", categoryRoutes);
mongoose.connect(
process.env.MONGODB_URL,
{
useCreateIndex: true,
useNewUrlParser: true,
useUnifiedTopology: true,
}.then,
console.log("MongoDB Successfully Connected")
);
app.use(express.json());
app.use(bodyParser.json() );
app.use(bodyParser.urlencoded({
extended: true
}));
app.get("/", (req, res) => {
res.status(200).send("Welcome to YouThrive Library Management App");
});
/* ---------------------------- */
app.listen(PORT, () => {
console.log(`Server running on PORT ${PORT}`);
})