Complete the code to access the query string parameter named 'name'.
app.get('/hello', (req, res) => { const userName = req.[1].name; res.send(`Hello, ${userName}!`); });
In Express, req.query holds the query string parameters from the URL.
Complete the code to send back the 'age' query parameter as a number.
app.get('/age', (req, res) => { const age = Number(req.[1].age); res.send(`You are ${age} years old.`); });
Query parameters are accessed via req.query. They are strings by default, so convert to number if needed.
Fix the error in accessing the 'search' query parameter.
app.get('/search', (req, res) => { const term = req.[1].search; res.send(`Searching for: ${term}`); });
The search parameter is part of the query string, so it must be accessed via req.query.
Fill both blanks to create a response showing 'category' and 'page' from query strings.
app.get('/items', (req, res) => { const category = req.[1].category; const page = Number(req.[2].page); res.send(`Category: ${category}, Page: ${page}`); });
req.params and req.queryBoth category and page come from query strings, so use req.query for both.
Fill all three blanks to create a filtered list using 'type', 'sort', and 'limit' query parameters.
app.get('/filter', (req, res) => { const type = req.[1].type; const sort = req.[2].sort; const limit = Number(req.[3].limit); res.send(`Filter: type=${type}, sort=${sort}, limit=${limit}`); });
All these values come from the query string, so use req.query for each.