Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When use npm cache and why?

Tags:

node.js

npm

When do I have to use npm cache clean ? And, why after using npm cache clean do I get info trying ?

info trying registry request attempt 1 at 09:54:07

http GET https://registry.npmjs.org/delayed-stream/latest
http 304 https://registry.npmjs.org/delayed-stream/latest
like image 390
Twinsen Avatar asked Dec 30 '13 08:12

Twinsen


1 Answers

Npm caches packages into a directory (~/.npm on Linux/OS X and %AppData%/npm-cache on Windows).

This helps when you have multiple nodejs based setups requiring various packages as dependencies. Npm wouldn't download a package which is already in the cache, instead would use the package from the cache if it's already there. Hence, in this case, it tries to optimise on the number of downloads it has to do.

Now, about when do you use npm cache clean. I've used it when for some reason my cache gets corrupted with some conflicting versions of different dependencies, or you simply want to clean up packages which you know you're not going to require at all, like maybe older versions of certain dependencies.

Basically, after using npm cache clean, it's like having a fresh installation of nodejs/npm with the exception of node modules installed globally (those will stay until you until you remove them with the npm uninstall command).

Additional info: https://docs.npmjs.com/cli/cache#configuration

like image 71
ausmarton Avatar answered Oct 14 '22 22:10

ausmarton