Url. parse method in node. js instructions for use _ node. js

Source: Internet
Author: User
This article mainly introduces node. url in js. description of the parse method. This article describes the url. parse method description, syntax, receive parameters, use instances, and implement Source Code. For more information, see Method description:

Converts a URL string to an object and returns it.

Syntax:

The 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:

The 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'
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.