Node Package Manager, or npm is an integral part of the modern JavaScript apps. Anytime you install an npm package, the package manager will cache the files for faster access in the future. Let’s see how you can save disk space by clearing the NPM cache.

Start by checking how much space is occupied by npm cache.

npm cache verify

You’ll see the number of cached npm modules, and the total amount of space they occupy.

Cache verified and compressed (~/.npm/_cacache):
Content verified: 62 (6743988 bytes)
Index entries: 62
Finished in 0.17s

To clean the npm cache run the clean command with the --force flag.

npm cache clean --force

Wait until the cleanup is done, and verify cache once again.

npm cache verify

This time, all you’ll see will be zeros.

Cache verified and compressed (~/.npm/_cacache):
Content verified: 0 (0 bytes)
Index entries: 0
Finished in 0.014s

Congratulations! You npm cache is clean!