Delete the node_modules directory faster


The above conversation on Twitter shows the problem and the solution.

The longer version

I have lost so much time when deleting Angular projects because of the tens of thousands of items in the node_modules directory. I mistakenly thought the number of files was overwhelming Windows. However it is not Windows that has the problem but File Explorer.

Previously my workflow for deleting the node_modules directory was to use Windows File Explorer to locate it then hit delete. Wait, then go and make a cup of coffee, come back and check on it’s progress. Still preparing to recycle, right go and put some washing on. Come back and check again. Brilliant it’s finished. Now what was I working on…

File explorer calculating the number of items to delete

Instead of using delete from File Explorer, using Remove Directory from the command line reduces the time taken to delete the nodes_module directory to almost zero.

RD /s node_modules 

The /s switch deletes a directory tree (the specified directory and all its sub directories, including all files).

My revised workflow is now to use File Explorer to find the directory.

Enter cmd in the location bar to start a new console in this directory.

Enter and run the command:

RD /s node_modules 


David Fowler for the tweet and Scott Hanselman for the answer.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.