Complete the code to access the query parameter named 'name' from the request.
app.get('/hello', (req, res) => { const name = req.query.[1]; res.send(`Hello, ${name}!`); });
The query parameters are accessed via req.query. To get the value of the 'name' parameter, use req.query.name.
Complete the code to send back the value of the 'age' query parameter as a number.
app.get('/age', (req, res) => { const age = Number(req.query.[1]); res.send(`Your age is ${age}`); });
The query parameter is named 'age', so use req.query.age. Wrapping it with Number() converts the string to a number.
Fix the error in accessing the 'search' query parameter correctly.
app.get('/search', (req, res) => { const term = req.[1].search; res.send(`Searching for: ${term}`); });
Query parameters are accessed via req.query. Using req.params or others will not get query string values.
Fill both blanks to parse 'page' and 'limit' query parameters as numbers.
app.get('/items', (req, res) => { const page = Number(req.query.[1]); const limit = Number(req.query.[2]); res.send(`Page: ${page}, Limit: ${limit}`); });
The query parameters are named 'page' and 'limit'. Use req.query.page and req.query.limit and convert them to numbers.
Fill all three blanks to parse 'sort', 'order', and 'filter' query parameters and send a summary.
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}`); });
Use the exact query parameter names: 'sort', 'order', and 'filter' to access their values from req.query.