Home > OS >  rimraf Error: invalid rimraf options. Unable to delete files automatically
rimraf Error: invalid rimraf options. Unable to delete files automatically

Time:02-05

I have an issue of multer depositing some files after it has been uploaded to cloudinay. I then found a post Screenshot of terminal with error

Please have a look at the code, the error is line 16 from the stack trace which is => return rimraf(path.join(uploadsDir, file), function (err)

const rimraf = require("rimraf");
const path = require("path");
const fs = require("fs");

var uploadsDir = path.normalize(__dirname   "/public/images");
fs.readdir(uploadsDir, function (err, files) {
  files.forEach(function (file, index) {
    fs.stat(path.join(uploadsDir, file), function (err, stat) {
      var endTime, now;
      if (err) {
        return console.error(err);
      }
      now = new Date().getTime();
      endTime = new Date(stat.ctime).getTime()   3600000;
      if (now > endTime) {
        return rimraf(path.join(uploadsDir, file), function (err) {
          if (err) {
            return console.error(err);
          }
          console.log("successfully deleted");
        });
      }
    });
  });
});

I am quiet amazed because I can't find the issue and not one has reported my experience. Please help

CodePudding user response:

from the documentation, it seems the second parameter( if you are using version 4) that should be passed to the function is the options object, while you are passing a function, check this URL

  • Related