0

I'm trying to post formdata with help of fetch api. Code :

var formData = new FormData();
formData.append("nickname", "johxns");
formData.append("password", "john_password");
formData.append("email", "john@server.com");


fetch("http://example/page", {
    body: formData,
    method: "post"
})

But in backend I'm recieving empty req body { }. An object can be posted but why can't I post form data. How to get this form data in backend.

karthi keyan
  • 1
  • 1
  • 4
  • then your problem is rather _parsing_ form data: [Parsing Post Form Data Node.js Express](https://stackoverflow.com/questions/30654747/parsing-post-form-data-node-js-express) – traynor Nov 15 '22 at 19:11

1 Answers1

1

You need to tell that you are sending form data not just body. Add

headers: {
        "Content-Type": "application/x-www-form-urlencoded",
    },
user2555515
  • 779
  • 6
  • 20