0

I haven't had this problem before and I've been doing it this way a long time.
(Angular Frontend)


const myFormData = new FormData();
myFormData.append("ok","true");
this.http.put(my_Express_backend_url,myFormData);

(Express Backend)

body-parser=require('body-parser');
...

console.log(req.body.ok)
undefined

everything is hitting right, the routes, the controller, it's getting to the proper function, but for some reason it does not work with the form data. I've used this method many times before and it is almost entirely identical yet I receive the undefined for the function i just wrote.

for now I am simply using javascript objects to pass info, eg:

const wantFormData={ok:'false'};
this.http.post(my_url,wantFormData);

...

console.log(req.body.ok);
...
false

But if somebody can help me get this back to normal I would greatly appreciate it! Thank you!

1 Answers1

0

I think body-parser only works with JSON or text data. Take a look at http://expressjs.com/en/resources/middleware/body-parser.html and Parsing Post Form Data Node.js Express

For parsing FormData, you might need another package.

Rob Bailey
  • 920
  • 1
  • 8
  • 23
  • But the backend is currently working with other FormData() objects in the format of req.body.<_x_ > So I don't think I need to add anything new, but rather something in the way disabling the functionality or something unique that disables its ability to read this format of request contents. – Jon Atollah Apr 02 '21 at 18:18