node之url模块
为什么用url模块
url模块是处理整个url的,url形式有"/api?username=zll&paw=123456"或""127.0.0.1:8900/api?username=zll&paw=123456""
const http = require("http");
const url = require("url");
let server = http.createServer(function (req, res) {
// http://localhost:8000/abc?username=abc&psw=123
console.log(req.url); // /abc?username=abc&psw=123
let result = url.parse(req.url, true);
console.log(result.query.psw);
});
// 监听
server.listen(8000);
浙公网安备 33010602011771号