Description of the url. parse method in node. js, node. jsurl. parse
Method description:
Converts a URL string to an object and returns it.
Syntax:
Copy codeThe Code is as follows:
Url. parse (urlStr, [parseQueryString], [slashesDenoteHost])
Receiving parameters:
UrlStr url string
When parseQueryString is true, the query module is used to analyze the query string. The default value is false.
SlashesDenoteHost
The default value is false. A string in the format of // foo/bar will be interpreted as {pathname: '// foo/bar '}
If it is set to true, strings in the format of // foo/bar will be interpreted as {host: 'foo', pathname: '/bar '}
Example:
Copy codeThe Code is as follows: var url = require ('url ');
Var a = url. parse ('HTTP: // example.com: 8080/one? A = index & t = article & m = default ');
Console. log ();
// Output result:
{
Protocol: 'http ',
Auth: null,
Host: 'example. com: 8080 ',
Port: '123 ',
Hostname: 'example. com ',
Hash: null,
Search :'? A = index & t = article & m = default ',
Query: 'A = index & t = article & m = default ',
Pathname: '/one ',
Path: '/one? A = index & t = article & m = default ',
Href: 'http: // example.com: 8080/one? A = index & t = article & m = default'
}