-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
36 lines (25 loc) · 918 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
const express = require("express")
const mongoose = require("mongoose")
const bodyParser = require("body-parser") // convert any req to JSON
const userRouter = require("./Routers/user")
const bookRouter = require("./Routers/book")
const app = express()
app.use(bodyParser.json())
const url = "mongodb+srv://Ahm-Dev1:123auth123@authentication.nbezokz.mongodb.net/?retryWrites=true&w=majority&appName=Authentication"
const connectDB = async () =>{
try{
mongoose.set("strictQuery", false)
await mongoose.connect(url)
console.log("Connected to Mongo DB")
}catch (err){
console.log("error while connecting to DB" + err)
process.exit()
}
}
connectDB()
app.use('/', userRouter)
app.use('/', bookRouter)
app.use(function(req, res){ // if endpoint not found -> Do this
res.status(404).send({ url: req.originalUrl + " " + "Page not Found"})
})
app.listen(8085)