What is the best way to delete several files in node.js?
function deleteFiles(files, callback){
...
}
var files = [\'file1.js\', \'file2.jpg\', \'file3.css\
You can use this to delete multiple files (for linux env ES6 syntax)
import {execSync} from "child_process";
...
...
const files = ['file1.js', 'file2.jpg', 'file3.css'];
// just example path
const rootDir = '/var/www/files/';
if (files.length > 0)
execSync('rm -f' + files.map(o => rootDir + o.replace(/(\s+)/g, '\\$1')).join(' '));
rm -f to ignore if files are missing and replace to escape spaces if file names contains it,