0
0
Expressframework~5 mins

Query string parsing in Express - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a query string in a URL?
A query string is the part of a URL after the question mark (?) that contains key-value pairs used to send data to the server.
Click to reveal answer
beginner
How does Express.js parse query strings by default?
Express.js automatically parses query strings into an object accessible via req.query in route handlers.
Click to reveal answer
beginner
Example: What does req.query contain for URL /search?term=books&sort=asc?
{ term: 'books', sort: 'asc' } - an object with keys and values from the query string.
Click to reveal answer
beginner
How can you access a specific query parameter in Express?
Use req.query.parameterName. For example, req.query.term gets the value of the 'term' parameter.
Click to reveal answer
beginner
What happens if a query parameter is missing in the URL?
The corresponding key in req.query will be undefined or not present, so you should check before using it.
Click to reveal answer
In Express.js, where do you find parsed query string parameters?
Areq.params
Breq.body
Creq.query
Dreq.headers
What symbol starts the query string in a URL?
A?
B&
C#
D/
If the URL is '/items?category=books&price=low', what is req.query.price?
Abooks
Blow
Ccategory
Dundefined
What type of data is req.query in Express?
AObject
BString
CArray
DNumber
If a query parameter is missing, what does req.query.parameter return?
Aerror
Bnull
Cempty string
Dundefined
Explain how Express.js handles query string parsing and how you access query parameters in a route.
Think about how URLs send extra data and how Express makes it easy to read.
You got /4 concepts.
    Describe what happens if a query parameter is not included in the URL and how your Express code should handle it.
    Consider what happens when you ask for something that isn't there.
    You got /3 concepts.