What is rimraf and how to use it in Node.js

The rimraf command is an alternative to the Linux command rm -rf. It allows you to do deep recursive deletion of files and folders.

Global rimraf installation

You can install rimraf globally using npm. It’s a common module, so you can insta…


This content originally appeared on DEV Community and was authored by Coderslang: Become a Software Engineer

The rimraf command is an alternative to the Linux command rm -rf. It allows you to do deep recursive deletion of files and folders.

Global rimraf installation

You can install rimraf globally using npm. It’s a common module, so you can install it on any operating system that supports npm. Windows, Linux, macOS - you shouldn’t have any issues here.

> npm install rimraf --global

Now you can use the command rimraf from the command line.

> rimraf ./node_modules

Such a call will delete the directory node_modules and all its content.

Using rimraf in the Node.js project

Also, you can save rimraf in your current Node.js project and use it in JavaScript code.

> npm install rimraf --save

This becomes handy when you need to delete some data that became obsolete.

import rimraf from 'rimraf';

// ...
// ...
// ...

.finally(() => {
        rimraf(`./${userIdFolder}/`, () => console.log(`DELETED ./${userIdFolder}/`));
      });

Such a call can be attached to the Promise chain and will delete users' data when the processing is over and we don’t need it anymore.

Learn Full Stack JavaScript


This content originally appeared on DEV Community and was authored by Coderslang: Become a Software Engineer


Print Share Comment Cite Upload Translate Updates
APA

Coderslang: Become a Software Engineer | Sciencx (2021-03-13T13:00:38+00:00) What is rimraf and how to use it in Node.js. Retrieved from https://www.scien.cx/2021/03/13/what-is-rimraf-and-how-to-use-it-in-node-js/

MLA
" » What is rimraf and how to use it in Node.js." Coderslang: Become a Software Engineer | Sciencx - Saturday March 13, 2021, https://www.scien.cx/2021/03/13/what-is-rimraf-and-how-to-use-it-in-node-js/
HARVARD
Coderslang: Become a Software Engineer | Sciencx Saturday March 13, 2021 » What is rimraf and how to use it in Node.js., viewed ,<https://www.scien.cx/2021/03/13/what-is-rimraf-and-how-to-use-it-in-node-js/>
VANCOUVER
Coderslang: Become a Software Engineer | Sciencx - » What is rimraf and how to use it in Node.js. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/13/what-is-rimraf-and-how-to-use-it-in-node-js/
CHICAGO
" » What is rimraf and how to use it in Node.js." Coderslang: Become a Software Engineer | Sciencx - Accessed . https://www.scien.cx/2021/03/13/what-is-rimraf-and-how-to-use-it-in-node-js/
IEEE
" » What is rimraf and how to use it in Node.js." Coderslang: Become a Software Engineer | Sciencx [Online]. Available: https://www.scien.cx/2021/03/13/what-is-rimraf-and-how-to-use-it-in-node-js/. [Accessed: ]
rf:citation
» What is rimraf and how to use it in Node.js | Coderslang: Become a Software Engineer | Sciencx | https://www.scien.cx/2021/03/13/what-is-rimraf-and-how-to-use-it-in-node-js/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.