An Interest In:
Web News this Week
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
- April 18, 2024
March 13, 2021 01:00 pm GMT
Global
Original Link: https://dev.to/coderslang/what-is-rimraf-and-how-to-use-it-in-node-js-ai0
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
. Its a common module, so you can install it on any operating system that supports npm
. Windows, Linux, macOS - you shouldnt 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 dont need it anymore.
Original Link: https://dev.to/coderslang/what-is-rimraf-and-how-to-use-it-in-node-js-ai0
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To