Web Development

Remove All of the node_modules Directories

Installing Node.js packages can take up a lot of space on your hard drive. Using the find command, we can traverse a directory tree and then use rm to delete all of the node_modules directories.

Warning Make sure you don't have any directories named node_modules that you need to hold on to!

find . -name "node_modules" \
  -type d \
  -prune \
  -print \
  -exec rm -rf '{}' +;

Note: The . part of the command means to search the current working directory, so it will search all of the node_modules folders from wherever you run this command. You can replace this with any path on your computer.