Basic Node and Express - Get Data from POST Requests

Tell us what’s happening:
Hi all! I’m back again lol… my second time asking for help in the forum. I’m stuck on the last challenge, not sure how to move past it. Help is much appreciated

Your project link(s)

solution: boilerplate-express - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15

Challenge: Basic Node and Express - Get Data from POST Requests

Link to the challenge:

Hello! I think I found the error.

Screenshot 2023-01-15 at 21.27.44

The firstname and lastname variables were not defined. You have to define them first before using them.

Okay thank you… I’d check it out now… I’ve been so occupied with school, I haven’t had the time to continue with the course

I just tried doing this and still fails the test;

app.post("/name", function(req, res) {
  // Handle the data in the request
const firstName = req.query.first;
  const lastName = req.query.last;
  // Use template literals to form a formatted string
  res.json({
    name: `${firstName} ${lastName}`
//   res.json({ name: req.body.first + " " + req.body.last });
// });

Try using req.body instead of req.query

Yes this is probably the solution. I literally just finished this 5 minutes ago.

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