Nodejs Processing URL Tool

Source: Internet
Author: User

The URL module provides 3 methods:parse,format,resolve

1. Parse

To introduce the URL module first

>url. Parse (' Http://www.cnblogs.com/cate/108703?from=scott&course=node#floor ')

Returns a JSON object that contains the various data for the URL

If the second parameter is set to true, query becomes an object. This parameter sets whether to use the QueryString module to process the query string.

QueryString methods for extracting objects from strings are: Parse, encode, etc.

Parse: Turn the string into an object, note that the URL module is different from the parse, part of the Knowledge URL module.

Encode: Converting a JSON object into a query string

2. Format

If there is a JSON object in hand, how to change back to the URL?

Use the url.format () function.

Sometimes, version agreements are not known . How does parsing not go wrong?

If the address is://imooc.com/course/list

Set the first three parameters to True, (false by default)

, three-time parameter change:

3, resolve (not sure)

Url.resolve (From,to)

Original address, Next level address

Online check, these are output the same results, that is, the first result. But I'm running it, really.

If anyone knows why, please tell.

The article is my study note, if there is a mistake, look

Nodejs Processing URL Tool

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.