-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (34 loc) · 898 Bytes
/
index.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
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
const port = 3000;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
const printRequest = (req, res) => {
console.log("Request");
console.log(req.body);
res.json({ ...req.body });
};
app.get("/", (req, res) => {
console.log("GET request");
printRequest(req, res);
});
app.put("/", (req, res) => {
console.log("PUT request");
printRequest(req, res);
});
app.post("/", (req, res) => {
console.log("POST request");
printRequest(req, res);
});
app.delete("/", (req, res) => {
console.log("DELETE request");
printRequest(req, res);
});
app.patch("/", (req, res) => {
console.log("PATCH request");
printRequest(req, res);
});
app.listen(port, () =>
console.log(`Hello world, app is listening on port ${port}!`)
);