What is the best way to delete several files in node.js?
function deleteFiles(files, callback){
...
}
var files = [\'file1.js\', \'file2.jpg\', \'file3.css\
I personally like shortcode (in one line)
files.forEach(path => fs.existsSync(path) && fs.unlinkSync(path))
So maybe using async/await style it's easier (complete example):
try {
var files = ['file1.js', 'file2.jpg', 'file3.css'];
files.forEach(path => fs.existsSync(path) && fs.unlinkSync(path))
// success code here
} catch (err) {
// error handling here
console.error(err)
}