-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
37 lines (31 loc) · 958 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
const express = require("express")
const app = express()
const mongoose = require("mongoose")
const mySchema = require("./mySchema")
const url = "mongodb+srv://admin-souvik:test123@cluster0.zr3n6.mongodb.net/Test?retryWrites=true&w=majority"
mongoose.connect(url).then(() => console.log("Connected to DB !"))
app.use(express.json())
app.post("/add-new-post", async (req, res) => {
const BookName = req.body.bookname;
const Name = req.body.nameofissuer;
const DueDate = req.body.date;
try {
const newData = new mySchema(
{
bookname: BookName,
nameofissuer: Name,
date: DueDate
}
)
const savedData = await newData.save()
}
catch (err) {
req.json(err)
}
})
app.use("/", (req, res) => {
res.json(
{ "message": "Your express server is started !" }
)
})
app.listen(3000, () => console.log("Express Started !"))