Q: (Express js 4 Multer) check form fields (if empty) before file upload I was to check if form fields are empty and if  name is changed before uploading file but multer first upload the file and then req.body is filled. I am using multer as a middleware.
Upload.js
checkField: function(req, res, next) {
   //Here i want to check if req.body.field1, field2 are empty or not
   //If empty res.send('Required fields are empty');
   console.log(req.body); //This returns empty {}
},
module.exports = {
uploadFile: multer({
    limits: {
        files: 1
    },
    dest: '/upload/',
})
};

Router:
app.post('/upload', upload.checkField, upload.uploadFile, function(req, res){});


A: The middleware order is wrong if your goal is to check what was sent in the request. You can't view the parsed request body before it has been parsed. Try this order instead:
app.post('/upload', upload.uploadFile, upload.checkField, function(req, res){});

