title: How to convert JPG image to WEBP format in Node.js?
body: <p>I m trying to upload an image using react.Js and save that image in node.Js using multer middleware. This is working perfectly but now I want to convert that image to WEBP  format using webp-converter which is a small vice- versa.</p>
  <p>But I m getting this error :</p>
  <pre><code> Error: Command failed: E:\Zegal\node_modules\webp-converte
   ib/libwebp_win64/bin/cwebp.exe -q 80 2a3279b820cc23939eea0295228423ee-- 
   inspironal-quote-about-life-inspiring-words.jpg -o output.webp
   SHCreateStreamOnFileA(filename, STGM_READ, stream) failed 80070002
   Error opening input file 2a3279b820cc23939eea0295228423ee--inspirational-quo
   about-life-inspiring-words.jpg (80070002)
   OpenInputStream(filename, &amp;stream) failed 80070002
   cannot open input file '2a3279b820cc23939eea0295228423ee--inspirational-quot
   bout-life-inspiring-words.jpg'
   Error! Could not process file 2a3279b820cc23939eea0295228423ee--inspirationa
   uote-about-life-inspiring-words.jpg
   Error! Cannot read input picture file '2a3279b820cc23939eea0295228423ee--ins
   ational-quote-about-life-inspiring-words.jpg'
  </code></pre>
  <p>How can I solve this problem in node using multer and WEBP ? Is there any
  other solution for conversion ?</p>
  <pre><code>const multer = require('multer');
  const webp = require('webp-converter');
  const path = require('path');
  const storage = multer.diskStorage({
      destination: './public/images',
      filename(req, file, cb) {
          cb(null, `${file.fieldname}-${Date.now()}${path.extname(file.originalname)}`)
      }
  });
  
  const upload = multer({
      storage,
      fileFilter: function (req, file, cb) {
          checkFileType(file, cb)
      }
  }).single(&quot;image&quot;);
  
  checkFileType = (file, cb) =&gt; {
      console.log(&quot;check file&quot;, file);
      const requireMimetype = &quot;image/jpeg&quot;;
      const checkMimeType = file.mimetype == requireMimetype ? true : false;
      console.log(&quot;checkMimeType&quot;, checkMimeType);
      if (checkMimeType) {
          webp.cwebp(file.originalname, &quot;output.webp&quot;, &quot;-q 80&quot;, function (status) {
              console.log(status);
          });
          return cb(null, true)
      } else {
          cb(&quot;Error:Only jpg images are allowed.&quot;)
      }
  }
  
  module.exports = upload;
  </code></pre>