Remove directory which is not empty
There is a module for this called rimraf
(https://npmjs.org/package/rimraf). It provides the same functionality as rm -Rf
Async usage:
var rimraf = require("rimraf");
rimraf("/some/directory", function () { console.log("done"); });
Sync usage:
rimraf.sync("/some/directory");
As of Node.js 14.14.0, the recommended way is to use fs.rmSync
:
fs.rmSync(dir, { recursive: true, force: true });