Three methods of URL. Url.parse (), resolves the URL address, url.formate (), formats a URL object as a URL string, Url.resolve (), accepts two parameters, and stitching two parameters into a format that the browser can recognize.
1, the node environment input URL, the output URL of the above three methods.
2, Url.parse (' http://imooc.com/course/list ')
Parsing results:
{
Protocol: ' http: ',/* Underlying protocol */
slashes:true,/* whether there is a protocol for the double slash */
Auth:null,
Host: ' imooc.com ',/* domain or IP address */
port:null,/* Port number */
Hostname: ' imooc.com ',
Hash:null,
Search:null;
Query:null,
Pathname: '/course/list ',
Path: '/course/list ',
HREF: ' http://imooc.com/course/list '
};
Url.parse (' Http://imooc.com:8080/course/list?from=scott&course=node#floor1 ')
Formatting results:
{
Protocol: ' http: ',/* Underlying protocol */
slashes:true,/* whether there is a protocol for the double slash */
Auth:null,
Host: ' imooc.com:8080 ',/* domain or IP address */
port:8080,/* Port number */
Hostname: ' imooc.com ',
Hash:floor1,
Search: '? From=scott&course=node ';
Query: ' From=scott&course=node ',
Pathname: '/course/list ',
Path: '/course/list ',
HREF: ' Http://imooc.com:8080/course/list?from=scott&course=node#floor1 '
}
3, Url.format (
{
Protocol: ' http: ',/* Underlying protocol */
slashes:true,/* whether there is a protocol for the double slash */
Auth:null,
Host: ' imooc.com:8080 ',/* domain or IP address */
port:8080,/* Port number */
Hostname: ' imooc.com ',
Hash:floor1,
Search: '? From=scott&course=node ';
Query: ' From=scott&course=node ',
Pathname: '/course/list ',
Path: '/course/list ',
HREF: ' Http://imooc.com:8080/course/list?from=scott&course=node#floor1 '
}
)
Formatting results:
' Http://imooc.com:8080/course/list?from=scott&course=node#floor1 '
4, Url.resolve (' http://imooc.com ', '/course/list ');
Stitching results:
' Http://imooc.com:8080/course/list ';
5, the Url.parse () method can also pass in two parameters, false by default. When the second argument is set to true, query resolves to an object and is no longer a string; The third parameter can be passed in to resolve the address without knowing the underlying protocol.
node. JS learning process 2 (URL)