Quick way to delete node_modules folder on Windows

Sometimes, We want to delete the node_modules folder in windows for a fresh installation of packages.

node_modules contains a nested recursive folder, and the file count is very huge. Delete a node_module folder in windows is not the quickest and is time-consuming because of the following reasons.

Due to this, In Windows, The node_modules files are deleted in two phases.

  • Discovery phase: In this, It calculates the number of files and folder size before deleting the folders and files.
  • Progress status phase: It deletes the files by showing the progress bar from zero to 100%.

You can see the screenshot.

Fast and multiple ways to delete node_modules folder in windows

It does not happen with Linux and macOS, hence, It is the quickest in those OS. You can also check other posts on npm command deprecate option is deprecated

How to delete node_modules quickest and easiest in Windows?

There are many other ways to delete the folder and recursive subfolders.

  • use the rmdir command One of the easy ways is using the command line
RMDIR node_modules /S

Running the above command asks prompt dialog to take input, if you say YES, it deletes the folder.

A:\work\angular-convert-examples>RMDIR node_modules /S
node_modules, Are you sure (Y/N)? Y

In another way, without prompt, use /Q option

RMDIR node_modules /S /Q

It deletes the node_modules folder completely,

Does it the fastest? No, It takes some time to delete the recursive folder.

Then, How do you delete a folder quickly and easily?

  • use PowerShell recursive command

if you still want to do with the command line recursively,

Open Powershell and run the below command

rm node_modules -force -recurse

It is faster compared with the rmdir option.

  • use the rimraf package

rimraf package is the node package

run the below command globally.

npm install -g rimraf

Once installed, run the below command to delete node_modules.

rimraf node_modules

Conclusion

To Sum up, Learn different ways to delete node_module in windows.

The rimraf node package is the best and quick way to do it.