Reputation: 648
As per the docs, npm has both a global folder and a cache folder.
Global: Global installs on Unix systems go to {prefix}/lib/node_modules. Global installs on Windows go to {prefix}/node_modules
Cache: Cache files are stored in ~/.npm on Posix, or ~/npm-cache on Windows
I know that when I run npm install -g PACKAGE, PACKAGE is stored in the global folder. Then what is stored in the cache ? What is its purpose ?
Upvotes: 2
Views: 3928
Reputation: 756
The npm cache is just an HTTP cache. All HTTP requests are cached, so if you do npm install it does not have to access the network if it finds the package in the cache. This is useful when you are creating docker containers during your build process, because it speeds up the build considerably. If you clear the cache - the very first time after that your npm install will be slower until the cache has a copy of the packages that you need. The cache is both filled and accessed during npm install. Also if you have multiple projects that use the same versioned npm packages there would be only a single copy in cache for those packages. So it is a productivity gain.
Upvotes: 5
Reputation: 2027
Basically all metadata concerning installing packages (http data, some package data (installed package versions as npm runs through cache for verification whilst installing new packages)). Nothing that should concern you if you don't have any specific cache-related errors while installing new packages. Cache isn't cleaned itself so if you're running on a very-budgety-memory, might perhaps want to look into the size of the cache folder from time to time and remove it if needed via npm cache clear
.
Upvotes: 0