Skip to content

Commit 0c193bb

Browse files
committed
Merge branch 'development'
2 parents ecaa493 + 91b1cd9 commit 0c193bb

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

express/appbodyparser.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env node
2+
const express = require("express");
3+
const app = express();
4+
app.use(express.json());
5+
6+
app.post("/info", (req, res) => {
7+
console.log(req.body);
8+
res.json(req.body);
9+
});
10+
11+
app.listen(3000, () => {
12+
console.log("Application started on port 3000");
13+
});

express/apppostform.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env node
2+
const express = require("express");
3+
const path = require("path");
4+
5+
const app = express();
6+
app.use(express.static("public"));
7+
app.use(express.urlencoded({ extended: true }));
8+
9+
app.get("/", (req, res) => {
10+
11+
res.sendFile(path.join(__dirname, "public", "index.html"));
12+
});
13+
14+
app.post("/message", (req, res) => {
15+
16+
res.set({ "Content-Type": "text/plain; charset=utf-8" });
17+
18+
let name = req.body.name;
19+
let message = req.body.message;
20+
let output = `${name} says: ${message}`;
21+
22+
res.send(output);
23+
});
24+
25+
26+
app.listen(3000, () => {
27+
console.log("Application started on port 3000");
28+
});

express/postrequest.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env node
2+
const axios = require("axios");
3+
4+
async function makePostRequest() {
5+
let params = {
6+
first_name: "John",
7+
last_name: "Doe",
8+
email: "gardener"
9+
};
10+
11+
let res = await axios.post("http://localhost:3000/info/", params);
12+
13+
console.log(`Status code: ${res.status}`);
14+
console.log(`Status text: ${res.statusText}`);
15+
console.log(`Request method: ${res.request.method}`);
16+
console.log(`Path: ${res.request.path}`);
17+
console.log(res.data);
18+
}
19+
20+
makePostRequest();

express/public/index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Form</title>
6+
</head>
7+
<body>
8+
<form action="message" method="post">
9+
<div>
10+
<label>Name:</label>
11+
<input type="text" name="name">
12+
</div>
13+
<div>
14+
<label>Message</label>
15+
<input type="text" name="message">
16+
</div>
17+
<button type="submit">Send</button>
18+
</form>
19+
</body>
20+
</html>

0 commit comments

Comments
 (0)