5

So, I should delete all node_modules in my project(I want that the node_modules folder become completely empty). Just removing folder manually does not suit me.

I read that I can delete it with rm -rf node_modules/ BUT it does not work on WINDOWS.

How to delete it?

Ray
  • 1,539
  • 1
  • 14
  • 27
  • DEL /F /Q /A node_modules/ – Ray Jan 13 '20 at 04:14
  • Does this answer your question? [How to delete files/subfolders in a specific directory at the command prompt in Windows](https://stackoverflow.com/questions/1965787/how-to-delete-files-subfolders-in-a-specific-directory-at-the-command-prompt-in) – Ray Jan 13 '20 at 04:15
  • Does this answer your question? [Delete files or folder recursively on Windows CMD](https://stackoverflow.com/questions/12748786/delete-files-or-folder-recursively-on-windows-cmd) – RobC Jan 13 '20 at 08:28

2 Answers2

7

Deleting node_modules is as simple as writing the node_modules without a slash:

rm -rf node_modules

rm -rf node_modules shouldn't have a slash at the end /, and this worked for me even on Widows.

SherylHohman
  • 16,580
  • 17
  • 88
  • 94
Godstime
  • 365
  • 7
  • 14
  • 1
    This simple command works in Git Bash also `rm -rf node_modules`. – akshay_sushir Jan 31 '22 at 10:01
  • The `-rf` option tells it to also recursively delete non-empty directories and subdirectories, forcefully – SherylHohman Apr 27 '22 at 17:18
  • That should be peculiar to you, because, all the time, I had the course to use `-rf` prefix, it has never deleted any other file, say the specific file or folder it is prefixed with. Forcefully, yeah, but using just `rm` gives you a different error message. – Godstime Apr 28 '22 at 09:38
4

Installing globally rimraf will do the job.

npm install -g rimraf

From the docs:

If installed with npm install rimraf -g it can be used as a global command rimraf [ ...] which is useful for cross platform support.

So with installing this package, you can remove directories on all platforms(windows, linux).

All left to do is rimraf node_modules

Naor Levi
  • 1,713
  • 1
  • 13
  • 27