Fix Express body-parser req.body with formdata is empty object

October 08, 2020

formdata is empty object nodejs

To handle it via express use multer. Here is an example -https://www.npmjs.com/package/multer

Make sure to addenctype="multipart/form-data"on form element. Otherwise Multer will ignore it.

let multer = require('multer');
let upload = multer();

app.post('/save', upload.fields([]), (req, res) => {
  console.log( req.body );
  console.log( req.files );
  res.sendStatus(200);
});

Written by Manoj Bhardwaj who lives and works in Mohali Punjab (India). My stackoverflow