-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndex3.js
41 lines (36 loc) · 982 Bytes
/
Index3.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');
require ('./config');
const product = require('./product');
const app = express();
app.use(express.json()) //converts the data into JSON formate forom stream formate
//post API using mongoose
app.post("/create" , async (req,res)=>{
let data = new product(req.body);
let result = await data.save();
console.log(result);
res.send(result);
});
//get API using mongoose
app.get("/list" , async(req,res)=>{
let data = await product.find();
res.send(data);
});
// delete Api using mongoose
app.delete("/delete/:_id" , async(req , res)=>{
console.log(req.params)
let data = await product.deleteOne(req.params);
res.send(data);
});
// put API using mongoose
app.put("/update/:_id" , async(req , res)=>{
console.log(req.params);
let data = await product.updateOne(
req.params ,
{
$set:req.body
}
);
res.send(data);
});
const port= 8000;
app.listen(port);