The documentation for fs.rmdir is very short and doesn\'t explain the behavior of rmdir when the directory is not empty.
Q: What happens if I try to use
fs.rmdir is not recursive.
fs.rmdir
You could instead use a recursive fs.readdir module like readdirp in order to find all files and directories . Then remove all files, followed by all directories.
For an even simpler solution have a look at rimraf.