After setting up Nodejs and long usage, storage space will be reduced. One option do is to clear cache in NPM.
Purpose of NPM Cache
Whenever you perform any installation of NPM package into your project with `npm install <package>`, the package and its dependences will first be downloaded into `~/.npm/_cacache`. After which, the packages will then be installed into `node_modules` in your project.
The packages stored in `~/.npm/_cacache` will help to remove network access when you install the same package again within the system. Since NPM will use the cache files to install to your working directory. This will make installation faster if your network is slow.
Motivation for Clearing NPM Cache
- NPM will not clear cache by itself and will increase the storage use over time. Hence, there may times where your storage is small and want to increase space after setting up an application.
- Error may occurred in cache after long usage and due to corruption.
How to perform NPM Clear Cache
Step 1: Verify current cache status
$ npm cache verify // Example output Cache verified and compressed (~/.npm/_cacache) Content verified: 8268 (101329789614 bytes) Index entries: 8268 Finished in 0.175s
This command can be executed from any directory since it is accessing a common cache location. Do note that the timing it takes to execute verify command will depend on the amount of cache existing.
Step 2: Execute command to clear cache
npm cache clean --force
Step 3: Verify current cache status
$ npm cache verify // Example output Cache verified and compressed (~/.npm/_cacache) Content verified: 0 (0 bytes) Index entries: 0 Finished in 0.011s
Conclusion
We have explore how to easily perform NPM clear cache with 3 step.
No Responses Yet