node.js初识03

时间:2021-10-03 11:29:35

node中的url

var http = require("http");
var url = require("url"); var server = http.createServer(function(req,res){
var pathname=url.parse(req.url).pathname;
var query=url.parse(req.url).query;
console.log("pathname"+pathname);
console.log("query"+query);
res.end();
}); server.listen(3000,"127.0.0.1");

例如:请求链接是http://127.0.0.1:3000/abs/lskdjoas?bafg=125&h=1255

pathname指的就是/abs/lskdjoas
query指的是bafg=125&h=1255

但是无法识别链接中#号之后的内容