0
0
Expressframework~5 mins

req.params for route parameters in Express - Cheat Sheet & Quick Revision

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

req.params is an object in Express that holds route parameters from the URL. It lets you access dynamic parts of the route.

Click to reveal answer
beginner
How do you define a route parameter in Express?

You define a route parameter by adding a colon : before a name in the route path, like /user/:id. This means id is a variable part of the URL.

Click to reveal answer
beginner
Example: What does req.params.id contain if the route is /user/:id and the URL is /user/42?

req.params.id will contain the string "42". It captures the part of the URL that matches the :id parameter.

Click to reveal answer
intermediate
Can req.params hold multiple parameters? How?

Yes. You can define multiple parameters in the route like /user/:userId/book/:bookId. Then req.params will have both userId and bookId as keys.

Click to reveal answer
beginner
What type of data does req.params store for each parameter?

All route parameters in req.params are stored as strings, even if they look like numbers.

Click to reveal answer
How do you access the value of a route parameter named id in Express?
Areq.route.id
Breq.query.id
Creq.params.id
Dreq.body.id
What symbol is used to define a route parameter in Express routes?
A:
B#
C$
D@
If the route is /product/:productId/review/:reviewId, how do you get the review ID?
Areq.params.reviewId
Breq.query.reviewId
Creq.params.productId
Dreq.body.reviewId
What data type are route parameters in req.params?
ANumber
BObject
CBoolean
DString
Which of these URLs matches the route /user/:id?
A/user
B/user/123
C/user/123/profile
D/user?id=123
Explain how to use req.params to get dynamic values from a URL in Express.
Think about how URLs can have parts that change and how Express lets you capture those.
You got /4 concepts.
    Describe how multiple route parameters work in Express and how to access them.
    Imagine a URL with two dynamic parts, like user and book IDs.
    You got /4 concepts.