Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse variables in querystring using Express?

I have a request being sent to the server:

"/stuff?a=a&b=b&c=c" 

Using express, how do I get these values?

I have tried the following...

app.get( "/stuff?:a&:b&:c", function( req, res ){}); 

...however it does not seem to recognize the route.

Thanks (in advance) for your help.

like image 446
user1031947 Avatar asked Feb 03 '13 05:02

user1031947


People also ask

What is QueryString parse?

The querystring. parse() method is used to parse a URL query string into an object that contains the key and pair values of the query URL. The object returned does not inherit prototypes from the JavaScript object, therefore usual Object methods will not work.

Which module is used to parse the QueryString in Nodejs?

The Query String module provides a way of parsing the URL query string.


1 Answers

It's not a good idea to use a query string inside a route.

In Express logic you need create a route for "/stuff". The query string will be available in req.query.

like image 79
Dmitry Manannikov Avatar answered Sep 18 '22 23:09

Dmitry Manannikov