I am using Axios to send POST requests to my Express Application. I normally have a values object containing the inputs and when I send this values object to the backend, everything is working fine and I can grab these values from req.body. I tried to convert this values object to a FormData object.
let formData = new FormData();
Object.keys(values).map((key: string) => {
formData.append(key, values[key]);
});
I also logged the formData object by iterating through its entries and it's filled with the content of the values object. However, when I make this POST request, req.body comes as an empty object. After facing this problem, I've tried some solutions in the internet which mostly suggested adding the below lines to 'app.js' file in the Express Application. Sadly this didn't help as well.
// app.use(express.json());
// app.use(express.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
I also tried placing the header { 'content-type': 'application/json' }
in my post request but again couldn't make it.
I'd be glad if someone could help me with this one, thank you.