Get Data from POST Requests

Hello Everyone,

I am repeatedly getting the
“{
“name”: “undefined undefined”
}”

instead of the actual names. I tried all the solutions and am not getting the proper answer. Please help :sweat_smile:

Finally figured it out! I didn’t realize we had to input the name into the HTML form first in order to get the name.

It should be like this:

var bodyParser = require('body-parser');
var urlencodedParser = bodyParser.urlencoded({ extended: false })
app.post('/name', urlencodedParser, (req, res) => {
  let name = req.body.first + ' ' + req.body.last;
  res.json({name: name});
});
1 Like