Posts

Showing posts with the label fs-module

fs.rmdir() vs fs.rmdirSync() in Node.js

The main purpose of rmdir() and rmdirSync() methods in the fs module is to remove a directory. If you are going to use any of these two methods, you should also remember that using them it is only possible to remove an empty directory. In case your goal is to get rid of the folder which contains another files or directories you would need to install the additional fs-extra module that would add more features on top of the fs. You can use remove() method from the fs-extra module to delete directories that contain something. fs.rmdir(path, callback) Removes a directory asynchronously. If the directory isn’t empty the function will throw an exception. Passed Parameters: path – string, path to the directory which you want to remove. The function won’t work if you will pass a path to the file instead of the directory (will result in ENOENT error on Windows and an ENOTDIR error on POSIX) callback – function, returns an error. Source code:  function rmdir(path, call...