Similar to rimraf, but with a Promise API and support for multiple files and globbing. It also protects you against deleting the current working directory and above.
🐶
Support this project and improve your JavaScript skills with this great ES6 course by Wes Bos.
Try his free JavaScript 30 course for a taste of what to expect. You might also like his React and Sublime course.
Install
$ npm install del
Usage
constdel=require('del');(async()=>{constdeletedPaths=awaitdel(['tmp/*.js','!tmp/unicorn.js']);console.log('Deleted files and folders:\n',deletedPaths.join('\n'));})();
Beware
The glob pattern ** matches all children and the parent.
So this won't work:
You have to explicitly ignore the parent directories too:
const del = require('del');
(async () => {
const deletedPaths = await del(['tmp/*.js'], {dryRun: true});
console.log('Files and folders that would be deleted:\n', deletedPaths.join('\n'));
})();