Basic Node and Express - Use body-parser to Parse POST Requests

Tell us what’s happening:
Describe your issue in detail here.
pls how do i get this code to res.json the values, cos it sends, undefine first name and last, i have required and used the body-parser both with urlencoded and .json, it logs the values to the console but sends undefined to the client
Your project link(s)

app.post('/name', (req, res) => {
  const firstname = req.body.first;
  const lastname = req.body.last;
  console.log(firstname + " " + lastname)
  const names = firstname + " " + lastname
  res.json({name: names })
})

solution: boilerplate-express (1) - Replit

Your browser information:

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

Challenge: Basic Node and Express - Use body-parser to Parse POST Requests

Link to the challenge:

You need to use a template literal, defined with `` to pass variables inside an object declaration.

res.json({
    name: `${firstName} ${lastName}`
  });

(I might not be using the corrent technical language though)

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