-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
58 lines (39 loc) · 974 Bytes
/
index.js
File metadata and controls
58 lines (39 loc) · 974 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const express = require("express")
const yaml = require("yamljs")
const swagger= require("swagger-ui-express")
const res = require("express/lib/response")
const swaggerDoc = yaml.load("./app.yaml")
const app = express()
app.use(express.json())
const data = [
{
id:1,
name: "Esther"
},
{
id:2,
name: "John"
},
{
id:1,
name: "Samuel"
},
]
app.use("/doc", swagger.serve, swagger.setup(swaggerDoc))
app.get("/user", (req, res)=>{
res.status(200).json({msg:"get all", data:data})
})
app.post("addUser", (req, res)=>{
const add =[...data, req.body]
res.status(200).json({msg:"new use added", data:add})
})
app.get("/", (req,res)=>{
res.end("hello")
})
app.get("/user/:id", (req,res)=>{
const db = data.find((el) => el.id === parseInt(req.params.id))
res.status(200).json({msg:"get all", data:db})
})
app.listen(5000, ()=>{
console.log("server is ready")
})