forked from samirvithlani/nodejs-club3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
appbackup3.js
62 lines (47 loc) · 1.17 KB
/
appbackup3.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
app.get("/hello", (req, res) => {
res.send("Hello world");
});
app.post("/hello", (req, res) => {
var reqbody = req.body;
res.json({
message: "recoed added.",
data: reqbody,
});
//res.send("Hello world post")
//console.log(req.body.name)
});
app.delete("/hello/:id", (req, res) => {
console.log(req.params.id);
var id = req.params.id;
//res.send("Hello world delete.."+id)
//res.status(200).send(id+"..is deleted")
res.json({
id: id,
message: "is deleted",
});
});
app.put("/user/:id", (req, res) => {
try {
var id = req.params.id;
if (id == 1) {
throw new Error("user not found");
} else {
res.json({
message:"user updated",
id:id,
data:req.body.data
})
}
} catch (err) {
res.status(404).send(err.message);
}
});
app.get("/user/:name",(req,res)=>{
var name = req.params.name;
res.send("Hello "+name)
})
app.get("/employee/:name",(req,res)=>{
var name = req.params.name;
var employees = search.searchData(name)
res.json(employees)
})