25

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 node@5.0 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?

Mark Swardstrom
  • 17,217
  • 6
  • 62
  • 70
fcce
  • 1,034
  • 1
  • 12
  • 24

1 Answers1

10

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"

iHazCode
  • 622
  • 4
  • 15
  • 11
    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 real use cache? – fcce Jan 16 '18 at 07:24
  • 1
    please verify that "npm cache clean --force" is actually clearing your global cache. In windows, c:/users/username/AppData/Roaming/npm – iHazCode Apr 19 '19 at 19:06
  • I didn't understand what was meant by **do an `npm cache clean`. That will clean up anything not installed globally, for those you will have to explicitly do an "npm uninstall"**, but I ran checked the size of the `%USERPROFILE%\AppData\Roaming\npm-cache` folder befor running `npm cache clean --force` and after running it and see that it definitely removed a lot of data (cache). I know think the answer should say, **for those you will have to explicitly do an `npm -g uninstall`** – PatS May 14 '20 at 20:18
  • That’s a fair point. Cache clean will not uninstall Globally or other installed packages. What it will do is remove cached packages from the global cache located in the above mentioned roaming folder in the Windows environment – iHazCode May 16 '20 at 00:33