file path and delete file in nodejs file path and delete file in nodejs express express

file path and delete file in nodejs


fs.unlink takes a single file, so unlink each element:

list_of_files.forEach(function(filename) {  fs.unlink(filename);});

or, if you need sequential, but asynchronous deletes you can use the following ES5 code:

(function next(err, list) {  if (err) {    return console.error("error in next()", err);  }  if (list.length === 0) {    return;  }  var filename = list.splice(0,1)[0];  fs.unlink(filename, function(err, result) {    next(err, list);  });}(null, list_of_files.slice()));