Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does npm cache packages?

In my server, npm doesn't cache any package and cache directory is empty.

#www@iZ2zefuufnen6rfx7c81u7Z:~/.npm$ nvm current
v9.4.0
# www@iZ2zefuufnen6rfx7c81u7Z:~/.npm$ npm config get cache
/home/www/.npm
# www@iZ2zefuufnen6rfx7c81u7Z:~/.npm$ ls
anonymous-cli-metrics.json  _cacache  _locks

My npm config

www@iZ2zefuufnen6rfx7c81u7Z:~/.npm$ npm config ls
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/5.6.0 node/v9.4.0 linux x64"

; node bin location = /home/www/.nvm/versions/node/v9.4.0/bin/node
; cwd = /home/www/.npm
; HOME = /home/www
; "npm config ls -l" to show all defaults.

=====update

I found that after [email protected] npm stores cache data in an opaque directory within the configured cache, named _cacache.https://docs.npmjs.com/cli/cache

www@iZ2zefuufnen6rfx7c81u7Z:~/.npm$ du -h --max-depth=1
56M ./_cacache
4.0K    ./_locks
8.0K    ./node-sass
56M .

The _cacache directory is just 56MB

www@iZ2zefuufnen6rfx7c81u7Z:~/.npm$ npm cache verify
Cache verified and compressed (~/.npm/_cacache):
Content verified: 1164 (39196729 bytes)
Index entries: 1167
Finished in 1.321s

====update

Another test in my project. After run rm -rf node_modules && npm clean cache --force, then run npm install added 1551 packages in 171.389s. And then rm -rf node_modules && npm install added 1551 packages in 152.378s. Does npm really use cache?

like image 752
feng ce Avatar asked Jan 16 '18 04:01

feng ce


People also ask

Where are npm packages cached?

Anytime you install a package using npm, the package files and data will be saved as a . tar file in the npm cache folder (automatically configured during installation) to be reused later when you run the same npm install command. Your npm cache files will be stored under ~/. npm/_cacache folder by default.

What does npm cache?

npm-cache is a command line utility that caches dependencies installed via npm , bower , jspm and composer . It is useful for build processes that run [npm|bower|composer|jspm] install every time as part of their build process. Since dependencies don't change often, this often means slower build times.

Is it okay to delete npm cache folder?

Yes it is safe, I have deleted npm and npm-cache folder manually and reinstall node its working fine. No it's not necessary to reinstall node.

What does npm cache clean does?

clean: Delete all data out of the cache folder. Note that this is typically unnecessary, as npm's cache is self-healing and resistant to data corruption issues. verify: Verify the contents of the cache folder, garbage collecting any unneeded data, and verifying the integrity of the cache index and all cached data.


1 Answers

Global package cache is used by default. You should notice a difference in your install timings if you first do an "npm cache clean". That will clean up anything not installed globally, for those you will have to explicitly do an "npm uninstall"

like image 67
iHazCode Avatar answered Sep 20 '22 14:09

iHazCode