NodeJS url.parse (url) .query

In the nodejs documentation:

query: Either the "params" part of the query string, or the object processed by querystring. Example: 'query=string' or {'query':'string'}

Link: NodeJS URL

This part is confusing.

  • When will 'query=string' ?
  • When will this {'query':'string'} also occur?

I saw that when I do url.parse() , it automatically converts the parameters to an object. My code will be an error if I support only one format.

How to find out if url.parse() converts parameters in this format: 'query=string' ?

+4
source share
1 answer
 url.parse(urlStr, [parseQueryString], [slashesDenoteHost]) 

If you pass true as the second argument, it will also querystring query string using the querystring module, and you will get a {'query':'string'} object, otherwise the query string will not be parsed (default behavior) and you will get query=string

+5
source

All Articles