const queryString=require('querystring');
var result=queryString.parse('uname=jack&upwd=123');
console.log(result);
//http://localhost:8080/?uname=jack&upwd=123 获取路径 把数据转换成对象格式{uname:jack,upwd:123}
const http=require('http');
const querystring=require('querystring');
var server=http.createServer(function(req,res){
var GET={};
//切割 split('切割符')
var arr=req.url.split('?');//['/','uname=jack&upwd=123']
GET=querystring.parse(arr[1]);
console.log(GET);
})
server.listen(8080);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form action="http://localhost:8080" method="get">
<p>用户名: <input type="" name="uname"></p>
<p>密码: <input type="" name="upwd"></p>
<p><input type="submit" value="提交"></p>
</form>
</body>
</html>
//get 1.手动 2.querystring模块 parse()
//url 模块
var urlLib=require('url');
var result=urlLib.parse('http://www.baidu.com/index?a=3&b=5',true);
//console.log(result);
console.log(result.pathname);
console.log(result.query);
const http=require('http');
const url=require('url');
var server=http.createServer(function(req,res){
var obj=url.parse(req.url,true);
console.log(obj);
});
server.listen(8080);