Why can’t node.js grab the data from the front end?

  node.js, question

Node.js can’t capture the data of the front-end form and cry
Js code

var http=require("http");
 var url=require("url");
 var dns=require("dns");
 var fs=require("fs");
 var querystring=require("querystring");
 var postdata="";
 http.createServer(function(req,res){
 
 req.setEncoding("utf8");
 //var readPath=dirname plus "/"plus url.parse('a.html').pathname;
 var pathname=url.parse(req.url).pathname;
 
 if(pathname==="/"){
 res.writeHead(200,{'Content-Type':'text/html'});
 var indexpage=fs.readFileSync("a.html");
 //console.log(indexpage);
 res.end(indexpage);
 bracket
 if(pathname==="/about"){
 res.writeHead(200,{'Content-Type':'text/plain'});
 
 
 req.addListener("data",function(chunk){
 if(chunk){
 Postdataplus =chunk;
 console.log(chunk);
 bracket
 
 else
 console.log("no data emit")
 });
 req.addListener("end",function(postdata){
 var a=querystring.parse(postdata);
 console.log(postdata)
 console.log(a);
 res.end(a.text);
 });
 bracket
 
 
 console.log("Server has been running on port 3000");
 
 }).listen("3000","127.0.0.1");
 
 This is HTML code
 <!  DOCTYPE html>
 <html>
 <head>
 <meta charset="utf-8">
 <meta name="author" content="sinson">
 </head>
 <body>
 <form action="/about" method="get">
 <input type="text" name="text">
 < input type="submit" value= "submit" >
 </form>
 </body>
 </html>

Ask the great god for advice

You only dealt with itbodyPart of the data, but the front-end submission method isget
It is suggested to find outgetAndpostThe basic difference between …


After modification
app.js

var http = require("http");
 var url = require("url");
 var dns = require("dns");
 var fs = require("fs");
 var querystring = require("querystring");
 var postdata = "";
 http.createServer(function (req, res) {
 req.setEncoding("utf8");
 // var readPath=dirname plus "/"plus url.parse('a.html').pathname;
 var pathname = url.parse(req.url).pathname;
 if (pathname === "/") {
 res.writeHead(200, { 'Content-Type': 'text/html' });
 var indexpage = fs.readFileSync("a.html");
 // console.log(indexpage);
 res.end(indexpage);
 bracket
 if (pathname === "/about") {
 res.writeHead(200, { 'Content-Type': 'text/plain' });
 req.addListener("data", function (chunk) {
 if (chunk) {
 Postdataplus = chunk;
 console.log(chunk);
 } else
 console.log("no data emit");
 });
 Req.addlistener ("end", function () {//remove parameters
 var a = querystring.parse(postdata);
 console.log(postdata);
 console.log(a);
 res.end(a.text);
 });
 bracket
 }).listen("3000", "127.0.0.1");
 console.log("Server has been running on port 3000");  //It is better to mention outside

a.html

<!  DOCTYPE html>
 <html>
 <head>
 <meta charset="utf-8">
 <meta name="author" content="sinson">
 </head>
 <body>
 <form action="/about" method="POST"> <!  -change to POST-- >
 <input type="text" name="text">
 < input type="submit" value= "submit" >
 </form>
 </body>
 </html>