0

I have a frontend in Angular and a backend in node.js with express.

I am doing a POST request in Angular like so:

this.userDetails = {
  address: {
    city: "City"
    country: "CH"
    number: "8"
    road: "Road"
    zip: "1020"
  },
  details: {
    2FA: false
    email: "[email protected]"
    gender: "0"
    name: "User"
    surname: "Name"

  }
}
this.http.post(
  environment.paymentHook + '/customercreate',
  this.userDetails
).subscribe(
  res => resolve(res),
  err => resolve(err)
);

receiving it like so in the back:

app.use(express.json());
app.options('/customercreate', cors(corsOptionsDelegate), function (req, res) { 
  res.end(); 
});
app.post('/customercreate', cors(corsOptionsDelegate), async (request, response) => {
  const body = request.body; // --> this appears empty {} when it should have the this.userDetails content
});

Anybody knows what is my issue here?

9
  • What is this.userDetails when the call is made? Commented Jul 9, 2020 at 17:40
  • Maybe this helps? stackoverflow.com/questions/34444033/… Commented Jul 9, 2020 at 17:42
  • Try looking in your web browsers network tab and see if the http call looks correct. Your angular code looks correct assuming environment.paymentHook is right. Commented Jul 9, 2020 at 17:44
  • @MikeOne This is a really old answer. With the newest version of express there is no need to use bodyParser Commented Jul 9, 2020 at 17:44
  • @JimmyArroyo Yes, I receive the request on the server and am able to console.log a few things. But the req.body appears empty like {} Commented Jul 9, 2020 at 17:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.