DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,274 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for How to Safely Delete All Your Node Modules to Free Up Space
Jackson Reeves
Jackson Reeves

Posted on

How to Safely Delete All Your Node Modules to Free Up Space

  1. Open the directory on your computer where all your node_modules will be found (just cd into it from the command line)
  2. Run this line while within the above directory to see a list of all the node modules that it contains (along with how much space they’re taking up): find . -name "node_modules" -type d -prune | xargs du -chs
  3. Double check that nothing in the resulting list is a surprise (for me, none of them came from folders where I hadn’t created a Node project, which is exactly what I expected); also check to see how much total space they take up (it tells you at the bottom of the list; for me, it was 9.4 GB)
  4. Run this line to actually delete all the modules: find . -name "node_modules" -type d -prune | xargs du -chs
  5. It will take a long time for the above line to execute (for me, I think it took about 10 minutes); after, check your computer’s storage (for me, sure enough, I gained about 10 GB of free space)
  6. If you ever want to reinstall node modules for any repo (e.g., for an old project that you want to spruce up), just go to its folder and run npm i to reinstall all its dependencies (aka, node modules)

h/t Mark Pieszak

Top comments (0)

🌚 Browsing with dark mode makes you a better developer by a factor of exactly 40.

It's a scientific fact.