Help - Get Query Parameter Input from the Client

Help - Get Query Parameter Input from the Client
0

#1

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);
 });

#2

Please post a link to the challenge you are working on.

Thank you.


#3

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


#4

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


#5

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();