title: Node.js Multer with Imagemin for file compression
body: <p>This is my code :</p>
  
  <pre><code>const imagemin=require('imagemin');
  const imageminMozjpeg = require('imagemin-mozjpeg');
  const multer=require('multer');
  const upload=multer({storage:storage});
  var imageUpload=upload.single('file');
  var storage=multer.diskStorage(
  {
      destination:function(req,file,cb) 
      {
          cb(null,'./tempuploads/')
      },
      filename:function(req, file, cb) 
      {
          cb(null,file.originalname)
      }
  });
  exports.filecompressor=async(req,res)=&gt;
  {
      imageUpload(req, res, function(err) 
      {
          let filetoupload=req.file;
          let filename=filetoupload.originalname;
          if(err)
          {
              console.log(err)
          }
          let temppath="./tempuploads/"+filename;
          imagemin([temppath],
          {
              destination: './cachedimages/',
              plugins:[imageminMozjpeg({quality: 50})]
          }).then(result=&gt;
          {
              console.log(result)
          });
      });
  };
  </code></pre>
  
  <p>I want <code>imageUpload(req, res, function(err){});</code> to <code>return temppath</code> so that I can use <code>imagemin()</code> function outside it and add await to it.</p>
  
  <p>Can anybody please help me??</p>