npm cache add <package-name> not adding the package to the cache directory

888 Views Asked by At

I have a project using <package-name> package. After installing this package, is it cached automatically? And how can I check if it is cached? (When I navigate to the npm-cache folder, I see no directory named <package-name>) My second question is, when using the command: npm cache add <package-name>, and then navigating to the npm-cache directory, again I see nothing about <package-name> there. Why this happens?

2

There are 2 best solutions below

1
On

Run npm config command. You might have changed the default paths.

Command: $ npm run list

OR

$ npm run ls -l # for all

Look for prefix setting: prefix setting

// Outputs:

scope = ""
user-agent = "npm/6.7.0 node/v11.15.0 darwin x64"

; userconfig /Users/xdeepakv/.npmrc
prefix = "/Users/xdeepakv/.npm-global"

; node bin location = /Users/xdeepakv/Softwares/node-v11.15.0-darwin-x64/bin/node
; HOME = /Users/xdeepakv
; "npm config ls -l" to show all defaults.

Note: You can also check these in ~/.npmrc [mac/linux]

0
On

According to https://docs.npmjs.com/cli-commands/cache.html

There is currently no method exposed through npm to inspect or directly manage the contents of this cache. In order to access it, cacache must be used directly.

So you'd need to use something like https://www.npmjs.com/package/cacache to inspect the contents directly.