title: How to remove images from Cloudinary by Node.js Express?
body: <p>Upload and set default controller functions are working perfectly. However, we are trying to implement delete image from Cloudinary as well. How can it be done?
  In the documentation it was confusing. Here is the code:</p>
  
  <pre><code> const cloudinary = require('cloudinary');
      const HttpStatus = require('http-status-codes');
  
      const User = require('../models/userModels');
  
      cloudinary.config({
        cloud_name: 'name',
        api_key: 'key',
        api_secret: 'secret'
      });
  
      module.exports = {
        UploadImage(req, res) {
          cloudinary.uploader.upload(req.body.image, async result =&gt; {
            await User.update(
              {
                _id: req.user._id
              },
              {
                $push: {
                  images: {
                    imgId: result.public_id,
                    imgVersion: result.version
                  }
                }
              }
            )
              .then(() =&gt;
                res
                  .status(HttpStatus.OK)
                  .json({ message: 'Image uploaded successfully' })
              )
              .catch(err =&gt;
                res
                  .status(HttpStatus.INTERNAL_SERVER_ERROR)
                  .json({ message: 'Error uploading image' })
              );
          });
        },
  
        DeleteImage(req, res) {
      cloudinary.uploader.destroy(req.params.image, async result =&gt; {
        await User.update(
          {
            _id: req.user._id
          },
          {
            $pull: {
              images: {
                imgId: result.public_id,
                imgVersion: result.version
              }
            }
          }
        )
          .then(() =&gt;
            res
              .status(HttpStatus.OK)
              .json({ message: 'Image deleted successfully' })
          )
          .catch(err =&gt;
            res
              .status(HttpStatus.INTERNAL_SERVER_ERROR)
              .json({ message: 'Error deleting image' })
          );
      });
    },
  
        async SetDefaultImage(req, res) {
          const { imgId, imgVersion } = req.params;
  
          await User.update(
            {
              _id: req.user._id
            },
            {
              picId: imgId,
              picVersion: imgVersion
            }
          )
            .then(() =&gt;
              res.status(HttpStatus.OK).json({ message: 'Default image set' })
            )
            .catch(err =&gt;
              res
                .status(HttpStatus.INTERNAL_SERVER_ERROR)
                .json({ message: 'Error occured' })
            );
        }
      };
  </code></pre>
  
  <p>We are using Node.js Express with Mongoose. How can we include extra function here that will remove images? </p>