njsetn:collecting_post_data
var http = require("http");
var fs = require("fs");
http.createServer(function(req, res) {
if (req.method === "GET") {
res.writeHead(200, {"Content-Type": "text/html"});
fs.createReadStream("./pubic/form.html", "UTF-8").pipe(res);
} else if (req.method === 'POST') {
var body = "";
req.on("data", function(chunk) {
body += chunk;
});
req.on("end", function() {
res.writeHead(200, {"Content-Type": "text/html"});
res.end(`
<!DOCTYPE html>
<html>
<head>
<title>Form Results </title>
</head>
<body>
<h1>Your Form result</h1>
<p>${body}</p>
</body>s
</html>
`)
});
}
}).listen(3000);
console.log("Form server listening on port 3000")
njsetn/collecting_post_data.txt · Last modified: 2016/03/25 21:16 by leo