a The URL is complete, including the QueryString part (that is , the GET request query string part),thehash part
Http://127.0.0.1:3000/b.html?id=123#123
At this point the Req.url is:
In other words, querystring belong to Req.url, but hash does not belong.
Now we want the part of the file name
The built-in modules are available in node: URL, path, querystring they can all serve URL recognition
var http = require ("http"); var fs = require ("FS"); var url = require ("url"); Http.createserver ((req,res)+= {// to Object var urljson = url.parse (req.url); Console.log (Urljson); Res.end ("");}). Listen ("127.0.0.1");
The URL is:
Http://127.0.0.1:3000/haha/1.html?id=123&name= Xiao Ming &sex= man #abc
The objects that are output at this time are:
If you add url.parse (Req.url,true), the QueryString section will automatically become an object, so that we can deposit into the database or something.
Two additional modules: path, querystring they are all service URLs.
varHTTP = require ("http");varFS = require ("FS");varurl = require ("url");varPath = require ("path");varQueryString = Require ("querystring"); Http.createserver ((Req,res)={ //Convert the URL string into a JSON object. varUrljson =Url.parse (Req.url); //Get file path varpathname =Urljson.pathname; //Get Extended name varExtname =path.extname (pathname); //Get query string varQS =Urljson.query; //to query the object, and Url.parse plus true very similar varQsjson =Querystring.parse (QS); Console.log (pathname); Console.log (Extname); Console.log (Qsjson); Res.end ("");}). Listen (3000, "127.0.0.1");
URL module, path module, querystring module