0
0
Expressframework~10 mins

Route parameters in Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a route that captures a user ID parameter.

Express
app.get('/user/[1]', (req, res) => {
  res.send(`User ID is ${req.params.id}`);
});
Drag options to blanks, or click blank then click option'
A:id
B?id
C*id
D#id
Attempts:
3 left
💡 Hint
Common Mistakes
Using *id or ?id instead of :id
Forgetting the colon before the parameter name
2fill in blank
medium

Complete the code to access the route parameter named 'postId'.

Express
app.get('/post/:postId', (req, res) => {
  const postId = req.params.[1];
  res.send(`Post ID: ${postId}`);
});
Drag options to blanks, or click blank then click option'
Aid
Bparam
CpostId
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different parameter name than defined in the route
Trying to access req.params.id when the parameter is named postId
3fill in blank
hard

Fix the error in the route to correctly capture the 'category' parameter.

Express
app.get('/items/[1]', (req, res) => {
  res.send(`Category: ${req.params.category}`);
});
Drag options to blanks, or click blank then click option'
Acategory
B:category
C*category
D?category
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the colon before the parameter name
Using wildcard or optional parameter syntax incorrectly
4fill in blank
hard

Fill both blanks to define a route with two parameters and access them.

Express
app.get('/[1]/:[2]', (req, res) => {
  res.send(`Category: ${req.params.category}, ID: ${req.params.id}`);
});
Drag options to blanks, or click blank then click option'
Acategory
Bid
Cuser
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using parameter syntax for the first segment
Mixing up parameter names
5fill in blank
hard

Fill all three blanks to create a route with nested parameters and access them.

Express
app.get('/[1]/:[2]/[3]/:commentId', (req, res) => {
  res.send(`Post: ${req.params.postId}, Comment: ${req.params.commentId}`);
});
Drag options to blanks, or click blank then click option'
Aposts
BpostId
Ccomments
Dcomment
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular instead of plural fixed segments
Forgetting the colon before parameter names