Can we get the variables in query string in node.js just like we get in $_GET
in PHP?
I know that in node.js we can get the url in request. Is there any method to get query string parameters?
Can we get the variables in query string in node.js just like we get in I know that in node.js we can get the url in request. Is there any method to get query string parameters? |
||||
|
Yes you can:
|
|||||||||
|
Since you've mentioned Express.js in your tags, here is an Express-specific answer: use req.query. E.g.
|
|||||
|
In Express, use
That said, most of the time, you want to get the value of a parameter irrespective of its source. In that case, use:
The value of the parameter will be returned whether the variable was in the route parameters, query string, or the encoded request body. |
|||||||||||||
|
for expressJs you want to do
|
|||||||||||||||||
|
You should be able to do something like this:
|
|||
|
I learned from above posts and decided to use this code throughout my site
then you can just call
where the url for get should be
|
|||
|
An old question, but since I've stumbled into it as top result when searching for something similar, here are my two cents. A small nodejs http server listening on port 9080, parsing GET or POST data and sending it back to the client as part of the response.
Save it as parse.js and run it on the console by entering "node parse.js" |
|||
|
Piece of working code: (I'm sure it will help) app.js
init.html
|
||||
|