Basic Node and Express - Get Query Parameter Input from the Client

Tell us what’s happening:
I tried several different ways that solve correctly the exercise, seems to be a problem out of my hand that comes when correcting the exercise.

First try:
app.route(‘/name’).get(function(req, res) {
console.log(req.query);
var { first: firstName, last: lastName } = req.query;
res.json({ name: ‘${firstName} ${lastName}’});
})

Second try:
app.route(‘/name’).get(function(req, res) {
console.log(req.query);
res.json({ name: ‘${req.query.first} ${req.query.last}’})
})

Third try:
app.route(“/name”, function(req, res) {
var { first: firstName, last: lastName } = req.query;
res.json({ name: ‘${firstName} ${lastName}’})
})

And many others… That didn’t work no matter if console was already showing the expected results.
console

Please let me know how can I continue to advance with the course.
Thanks

Your project link(s)

solution: boilerplate-express (1) - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36

Challenge: Basic Node and Express - Get Query Parameter Input from the Client

Link to the challenge:

1 Like

Your first and second tries were almost correct. Third try you removed the GET request, so it won’t work at all.
The one critical issue is that your response object is trying to use template literal but you’ve used regular quote marks instead of backticks.
Amend either of your first two tries to include backticks and either should pass I think.
Also, the ‘var’ keyword has been superseded by ‘let’ and ‘const’ now, so I’d use ‘const’ in this situation.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.