Challenge - 5 Problems
Express Params Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does
req.params contain in this route?Consider this Express route:
What will be the output if a client requests
app.get('/user/:id', (req, res) => { res.send(req.params); });What will be the output if a client requests
/user/42?Express
app.get('/user/:id', (req, res) => { res.send(req.params); });Attempts:
2 left
💡 Hint
Look at how the route defines the parameter name after the colon.
✗ Incorrect
The req.params object contains key-value pairs where keys are the names defined in the route path. Here, :id means req.params will have a key id with the value from the URL.
📝 Syntax
intermediate2:00remaining
Which route correctly captures two parameters in
req.params?You want to capture both
category and itemId from the URL. Which route definition is correct?Attempts:
2 left
💡 Hint
Parameters are separated by slashes, not commas or ampersands.
✗ Incorrect
Express route parameters are defined by prefixing names with a colon and separating them by slashes. Option A correctly uses /:category/:itemId.
🔧 Debug
advanced2:00remaining
Why does
req.params not contain expected values?Given this code:
What happens when a client requests
app.get('/post/:postId', (req, res) => { res.send(req.params.post); });What happens when a client requests
/post/123?Express
app.get('/post/:postId', (req, res) => { res.send(req.params.post); });Attempts:
2 left
💡 Hint
Check the exact parameter name used in the route and in the code.
✗ Incorrect
The route defines the parameter as postId, but the code tries to access req.params.post. Since post is not defined, it returns undefined.
❓ state_output
advanced2:00remaining
What is the value of
req.params for this route and URL?Route:
URL requested:
What does
app.get('/files/:fileName.:ext', (req, res) => { res.send(req.params); });URL requested:
/files/report.pdfWhat does
req.params contain?Express
app.get('/files/:fileName.:ext', (req, res) => { res.send(req.params); });Attempts:
2 left
💡 Hint
Express supports dot-separated parameters in routes.
✗ Incorrect
The route uses :fileName.:ext to capture the file name and extension separately. For /files/report.pdf, fileName is 'report' and ext is 'pdf'.
🧠 Conceptual
expert2:00remaining
Which statement about
req.params is true?Choose the correct statement about
req.params in Express routes.Attempts:
2 left
💡 Hint
Think about how Express separates route parameters from query and body data.
✗ Incorrect
req.params holds only the parameters defined in the route path using colon syntax. Query parameters are in req.query, and body data is in req.body.