Save disk space by deleting node_modules

tags: [[JavaScript]]

pid: 211110190432

After developing on a computer for a while you'll probably end up with a bunch of projects. If those projects are [[JavaScript]] there's a good change that they contain a node_modules directory. From time to time it's a good idea to remove all of these folders, since they can get quite big, and re-download the dependencies in the projects you're actively using.
I have aliased the following command to node-prune and have been using it since [[2019-12-11]] without any issues. When I ran the command on [[2021-11-08]] I got back ~40 GB of disk space. Use it at your own risk.
alias node-prune='find . -name "node_modules" -type d -prune -exec rm -rf '{}' +'
If you just want to find and display the size of the folders you can use the following command
find . -name "node_modules" -type d -prune -print | xargs du -chs
There's also npkill which looks up and displays node_modules, displays their size and allows you to delete the folders. Run it by using npx npkill
I also posted this on my blog with explanations of the command.

Linked references
2021-11-10