Instructions for using the url.parse method in node.js
- 2020-03-30 04:36:18
- OfStack
Method description:
Converts a URL string into an object and returns it.
Grammar:
url.parse(urlStr, [parseQueryString], [slashesDenoteHost])
Receiving parameters:
UrlStr The url string
ParseQueryString Is true, the query module is used to analyze the query string, which defaults to false
SlashesDenoteHost
The default is false, and the string in the form of //foo/bar will be interpreted as {pathname: '//foo/bar'}
If set to true, the string in the form of //foo/bar will be interpreted as & PI; {host: 'foo', pathname:' /bar'}
Example:
var url = require('url');
var a = url.parse('http://example.com:8080/one?a=index&t=article&m=default');
console.log(a);
//Output:
{
protocol : 'http' ,
auth : null ,
host : 'example.com:8080' ,
port : '8080' ,
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'
}