Query fields are undefined

I have the following code. The Get request gets checked as correct, but Post returns “First is undefined”. It seems the get request did not grab the value of req.query.first. Why?
From the home page, both first name and last names fields in the form are filled, then I click Submit button.

app.get("/name", function(req, res){
console.log(“GET, Query is " + req.query);
var firstname = req.query.first;
var lastname = req.query.last;
res.json({name: ${firstname} ${lastname}});
})
app.post(”/name", function(req, res){
var string = req.body.first + " " + req.body.last;
res.json({name: string});
})

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36.

Challenge: Get Data from POST Requests

Link to the challenge:

Can you post a link to your full code?

In the previous challenge, see the following statement:

As usual, the middleware must be mounted before all the routes which need it.

Your current code does not mount the middleware in the correct location.

1 Like

@RandellDawson thanks so much!

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