title: req.body not working when using multipart/form-data in html form NodeJs/Express
body: <p>I am using <code>body-parser</code> to get info requested from forms, but when I put <code>enctype="multipart/form-data"</code> in the header of the form, the <code>req.body</code> will not working at all.</p>
  
  <p>However, I have used <code>multer</code> lib in order to upload images as follow:</p>
  
  <pre><code>app.post("/", function (req, res, next) {
    var button = req.body.button_name;
    if (button == "upload") {
      var UserId = 2;
      var imageUploadedLimited = 3;
      var storage = multer.diskStorage({
        destination: function (req, file, callback) {
          var dir = "./public/images/uploads/";
          if (!fs.existsSync(dir)) {
            fs.mkdirSync(dir);
          }
          dir = "./public/images/uploads/" + UserId;
          if (!fs.existsSync(dir)) {
            fs.mkdirSync(dir);
          }
          callback(null, dir);
        },
        filename: function (req, file, cb) {
          cb(null, file.fieldname + "-" + Date.now() + ".jpg");
        },
      });
      const maxSize = 1 * 1000 * 1000;
  
      var upload = multer({
        storage: storage,
        limits: { fileSize: maxSize },
        fileFilter: function (req, file, cb) {
          var filetypes = /jpeg|jpg|png/;
          var mimetype = filetypes.test(file.mimetype);
  
          var extname = filetypes.test(
            path.extname(file.originalname).toLowerCase()
          );
  
          if (mimetype &amp;&amp; extname) {
            return cb(null, true);
          }
  
          cb(
            "Error: File upload only supports the " +
              "following filetypes - " +
              filetypes
          );
        },
      }).array("filename2", imageUploadedLimited);
  
      upload(req, res, function (err) {
        if (err) {
          res.send(err);
        } else {
          res.send("Success, Image uploaded!");
        }
      });
    }
  });
  </code></pre>
  
  <p>If I print out the <code>button</code> variable from the second line, will show me <code>undefined</code> value. I know <code>body-parser</code> does not support <code>enctype="multipart/form-data"</code>. In this case, how I can see the value from the form?</p>