Help - Get Query Parameter Input from the Client

Hi, I doing this challenge and I keep getting the following message when I run the code:

// running tests

Test 2: “GET /name” route does not behave as expected

Test 1: “GET /name” route does not behave as expected

// tests completed

Below is my code. Please help.

app.get("/name", function(req, res) {
   var firstName = req.query.first;
   var lastName = req.query.last;
   var jsonObj = {name: 'firstName lastName'};
   res.send(jsonObj);
 });

Here is the link to the challenge:

https://learn.freecodecamp.org/apis-and-microservices/basic-node-and-express/get-query-parameter-input-from-the-client

You should look better the challenge’s tip. You have to chain the route() method with get() and post().

I tried that as well and I get the same result:

app.route('/name').get((req, res) => {
   var first = req.query.first;
   var last = req.query.last;
   var jsonObj = {name: '${first} ${last}'};
   res.send(jsonObj);
 }).post();

“GET /name” route does not behave as expected
Your API endpoint should respond with the correct name

EDIT:

It works now. Here’s the code for anyone who needs help:

app.route('/name').get((req, res) => {
   var first = req.query.first;
   var last = req.query.last;
   var jsonObj = {name: first + ' ' + last};
   res.send(jsonObj);
 }).post();
2 Likes