Basic Node and Express - Get Data from POST Requests

Tell us what’s happening:
Getting an error message:
Cannot read properties of undefined (reading ‘first’)
Console in browser shows:
POST https://fcc-boilerplate-express-2.rigo205.repl.co/name 500

Your code so far
app.post(“/name”, function(req, res) {
// Handle the data in the request
var string = req.body.first + " " + req.body.last;
res.json({ name: string });
});

Your browser information:

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

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

Link to the challenge:

My repl:
https://fcc-boilerplate-express-2.rigo205.repl.co/

Hi @rigo205

Perhaps share the link to your project’s source code instead of the live project.

I have tested your code but I don’t see any error.

Here is my code

Uncomment point number 12

Middleware has to be used before the routes. You need to use bodyParser before the route that needs it.

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