What is the best way to delete several files in node.js?
function deleteFiles(files, callback){
...
}
var files = [\'file1.js\', \'file2.jpg\', \'file3.css\
Here is a code to delete several files from directory in node.js,
var fs = require('fs');
var removeFile= function (err) {
if (err) {
console.log("unlink failed", err);
} else {
console.log("file deleted");
}
}
fs.unlink('filepath', removeFile); // for single file
//for multiple files...
_.map(yourArray,(files)=>{
fs.unlink('filepath', removeFile);
});