Free space by deleting node_modules

Node.js
Node.js
Node.js

Did you know you can free disk space by deleting node_modules?

To check the disk usage of your current working directory:

$ du -sh .

To find all directories (in your working directory) that matches the name node_modules:

$ find . -type d -name 'node_modules'

Execute recursive remove on all matches:

$ find . -type d -name 'node_modules' -exec rm -rf {} \;

Display the disk usage of your current working directory:

$ du -sh .

Example

Here’s an example of how to delete node_modules of a project bootstrapped by Create React App.

Create app:

$ npx create-react-app my-react-app

Check disk usage:

$ du -sh
248M .

Delete node_modules:

$ find . -type d -name node_modules -exec rm -rf {} \;

Check disk usage:

$ du -sh
924K .

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store