Paul
Paul

Reputation: 564

How do I delete node_modules folder quickly?

When I want to delete a node_modules folder it takes ages when I delete it using Windows Explorer. How do I delete faster?

Upvotes: 8

Views: 13302

Answers (3)

Ege Özel
Ege Özel

Reputation: 21

Running the command Remove-Item -Path "directory_or_file_path" -Recurse -Force instantly delete node_modules for me on VSCode. How to Delete Node Modules in VSCode?

Upvotes: 1

Pizaranha
Pizaranha

Reputation: 330

I use to have the same issue, taking hours to achieve the deletion until I found this workaround:

  1. Select the node_modules folder. Do this with the file explorer.

  2. Open Powershell as admin: press Alt+F, then S, then A.

  3. Wait and accept to open Powershell as admin

  4. Paste this command and press Enter: del /f/q/s *.* > nul.

WARNING

Please be sure to be in the folder node_modules. I mean, that the terminal path ends with ...\node_modules.

In the above command, we use the /f switch to force the deletion of read-only files. The /q switch enables quiet mode. The /s switch executes the command for all files in any folder inside the folder you’re trying to remove. Using *.* tells the del command to delete every file and > nul disables the console output improving performance and speed.

  1. Wait for the process to take action.

  2. Now go up one level in the directory with cd...

  3. Finally use this command to delete the node_modules folder rmdir /q/s node_modules

In the above command, we use the /q switch to enable quiet mode, the /s switch to run the command on all the folders, and node_modules is the variable you need to specify to delete the folder you want.


If you get an error with Powershell try other terminals as administrator like Windows Terminal, Command Prompt (cmd) or third party terminals like ConEmu. I made this steps with Cmder and all the deletion was done in just 5 minutes. Off course this duration is variable according to the size of the folder.


References:

pureinfotech.com

ConEmu

Cmder

Upvotes: 6

Paul
Paul

Reputation: 564

From you project folder use following command to delete it: rd .\node_modules\ /s /q

Upvotes: 2

Related Questions