-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (24 loc) · 702 Bytes
/
server.js
File metadata and controls
32 lines (24 loc) · 702 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
const express = require("express");
const app = express();
const data = require("./data.json");
/* */
app.use(express.json());
app.get("/clients", function (req, res) {
res.json(data);
console.log(typeof res);
});
app.get("/clients/:id", function (req, res) {
const { id } = req.params
const client = data.find(cli => cli.id == id)
if(!client){
return res.status(200).json({ erro: 'cliente não encontrado' });
}
res.json(client)
});
app.post("/clients", function (req, res) {});
app.put("/clients/:id", function (req, res) {});
app.delete("/clients/:id", function (req, res) {});
app.listen(3000, function () {
console.log("Server is running");
console.log(data);
});