Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS url.parse( url ).query

Tags:

node.js

In the nodejs documentation:

query: Either the 'params' portion of the query string, or a querystring-parsed object. Example: 'query=string' or {'query':'string'}

Link: NodeJS URL

This part is confusing.

  1. When will 'query=string' happens?
  2. When will this {'query':'string'} also happens?

I have seen that when I do url.parse() it automatically converts the parameters into an object. My code will be buggy if I only support one format.

How will I know if url.parse() converts the parameters in this format: 'query=string'?

like image 619
Richeve Bebedor Avatar asked Aug 14 '12 07:08

Richeve Bebedor


1 Answers

url.parse(urlStr, [parseQueryString], [slashesDenoteHost])

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

like image 127
mak Avatar answered Nov 15 '22 12:11

mak