0
0
Expressframework~5 mins

req.query for query strings in Express - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is req.query in Express?

req.query is an object in Express that holds the query string parameters sent in the URL of a GET request.

Click to reveal answer
beginner
How do you access a query parameter named name in Express?

You use req.query.name to get the value of the name parameter from the URL query string.

Click to reveal answer
beginner
Example URL: /search?term=books&sort=asc. How does req.query look?

req.query will be an object: { term: 'books', sort: 'asc' }.

Click to reveal answer
beginner
What type of data does req.query contain?

req.query contains all query parameters as strings inside an object. Even numbers or booleans come as strings.

Click to reveal answer
intermediate
Can req.query handle multiple values for the same key?

Yes, if the URL has repeated keys like ?tag=js&tag=node, req.query.tag will be an array: ['js', 'node'].

Click to reveal answer
What does req.query represent in Express?
AAn object containing URL query parameters
BThe body of a POST request
CThe headers of the HTTP request
DThe cookies sent by the client
How do you access the value of ?page=3 in Express?
A<code>req.headers.page</code>
B<code>req.query.page</code>
C<code>req.body.page</code>
D<code>req.params.page</code>
If the URL is /items?color=red&color=blue, what is req.query.color?
A'red'
Bundefined
C'blue'
D['red', 'blue']
What data type are values inside req.query?
AStrings
BNumbers
CBooleans
DObjects
Which HTTP method usually sends data accessible via req.query?
APUT
BPOST
CGET
DDELETE
Explain how req.query works in Express and how you use it to get query string values.
Think about how URLs have ?key=value and how Express reads that.
You got /5 concepts.
    Describe a real-life example where you might use req.query in a web app.
    Imagine a shopping site where you filter products by category or price.
    You got /4 concepts.