text: const multer = require("multer");
  const uuid = require("uuid").v1;
  
  const MIME_TYPE_MAP = {
    "image/png": "png",
    "image/jpeg": "jpeg",
    "image/jpg": "jpg",
  };
  
  const fileUpload = multer({
    limits: 500000,
    storage: multer.diskStorage({
      destination: (req, file, cb) => {
        cb(null, "uploads/images");
      },
      filename: (req, file, cb) => {
        const ext = MIME_TYPE_MAP[file.mimetype];
        cb(null, uuid() + "." + ext);
      },
      fileFilter: (req, file, cb) => {
        const isValid = !!MIME_TYPE_MAP[file.mimetype]; // convert undefined or null to false, and some type found into true
        let error = isValid ? null : new Error("Invalid mime type!");
        cb(error, isValid);
      },
    }),
  });
  
  module.exports = fileUpload;
  