Save Space by Automatically Deleting Your Old Node Modules

If you have a lot of projects on your computer chances are you also have a lot of node_modules folders laying around with TONS of files inside. For example, in just one project my node_modules folder is taking up 115,105,689 bytes (176.4 MB on disk) for 23,479 items. Multiply that by the two dozen or more projects you have laying around and it ends up being a massive amount of files just sitting there.

It would be nice to have a way of auto-deleting all those files on projects that have long been forgotten and Enrique Benitez has created a new tool to solve this problem. It’s called wipe-modules and can be installed through NPM:

npm install --global wipe-modules

After you have it installed just run the -h help command to get a list of options:

$ wipe-modules --help

  Usage: wipe-modules [path] [days]

  Path:
    The full path of your code directory

  Days:
    The days you want to set to mark projects as inactive

  Example: wipe-modules ~/code 30

  That will remove the node_modules of your ~/code projects
  whose been inactive for 30 days or more.

He’s also created a short video showing it in action:

What is great is this can also be setup to run as a CRON job so you can, set it and forget it, like Rob Popeil. If you are worried about space on your machine or tired of having all these files laying around this package will be a great solution. Plus since all the dependencies should be saved in your package.json there isn’t a real chance of loosing anything important.