Tuesday 20 June 2017

Newbie - req.body issues

I sent a JSON object to the /register route. It seems that the object is successfully sent; but... I can't seem to retrieve the values of the JSON object.Router:router.post("/register", function(req, res){ res.json(req.body); console.log(req.body); console.log("First Name:" + req.body.first_name); console.log("Last Name:" + req.body.last_name); console.log("Email:" + req.body.email); } Terminal:'{"age":84,"email":"test@gmail.com","first_name":"Matt","id":0,"last_name":"Louis","password":"lp334564a"}': '' }First Name:undefinedLast Name:undefinedEmail:undefinedWhen I use postman and visit the link of localhost:3000/register:It gave me this: { "{\n\t\"prop\":\"value\"\n}": "" } Any ideas what's wrong?

Submitted June 21, 2017 at 12:16AM by badboyzpwns

No comments:

Post a Comment