Skip to content

Commit dbe2d12

Browse files
use http.createServer and play with req-res
0 parents  commit dbe2d12

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Message.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hi message

app.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const http = require("http");
2+
const fs = require("fs");
3+
4+
const server = http.createServer((req, res) => {
5+
const url = req.url;
6+
if (url === "/") {
7+
res.write("<html>");
8+
res.write("<head><title>Enter Message</title></head>");
9+
res.write(
10+
"<body><form action='/message' method='POST'><input type='text' name='message'><button type='submit'>Send</button></form></body>"
11+
);
12+
res.write("</html>");
13+
return res.end();
14+
req.p;
15+
} else if (url === "/message" && req.method === "POST") {
16+
return fs.writeFile("Message.txt", "Hi message", () => {
17+
res.statusCode = 301;
18+
res.setHeader("Location", "/");
19+
return res.end();
20+
});
21+
}
22+
});
23+
24+
server.listen(3000);

0 commit comments

Comments
 (0)