0
0
Expressframework~10 mins

Query string parsing 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 access the query parameter named 'name' from the request.

Express
app.get('/hello', (req, res) => {
  const name = req.query.[1];
  res.send(`Hello, ${name}!`);
});
Drag options to blanks, or click blank then click option'
Aquery
Bparams
Cbody
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using req.params instead of req.query
Trying to access req.body for query parameters
2fill in blank
medium

Complete the code to send back the value of the 'age' query parameter as a number.

Express
app.get('/age', (req, res) => {
  const age = Number(req.query.[1]);
  res.send(`Your age is ${age}`);
});
Drag options to blanks, or click blank then click option'
Ayears
Bage
CuserAge
DageParam
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong parameter name
Not converting the string to a number
3fill in blank
hard

Fix the error in accessing the 'search' query parameter correctly.

Express
app.get('/search', (req, res) => {
  const term = req.[1].search;
  res.send(`Searching for: ${term}`);
});
Drag options to blanks, or click blank then click option'
Aquery
Bbody
Cparams
Dheaders
Attempts:
3 left
💡 Hint
Common Mistakes
Using req.params instead of req.query
Trying to get query parameters from req.body
4fill in blank
hard

Fill both blanks to parse 'page' and 'limit' query parameters as numbers.

Express
app.get('/items', (req, res) => {
  const page = Number(req.query.[1]);
  const limit = Number(req.query.[2]);
  res.send(`Page: ${page}, Limit: ${limit}`);
});
Drag options to blanks, or click blank then click option'
Apage
Blimit
Ccount
Dsize
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter names
Not converting to numbers
5fill in blank
hard

Fill all three blanks to parse 'sort', 'order', and 'filter' query parameters and send a summary.

Express
app.get('/data', (req, res) => {
  const sort = req.query.[1];
  const order = req.query.[2];
  const filter = req.query.[3];
  res.send(`Sort by: ${sort}, Order: ${order}, Filter: ${filter}`);
});
Drag options to blanks, or click blank then click option'
Asort
Border
Cfilter
Dtype
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names
Mixing parameter names with other properties