Alexander Mills
Alexander Mills

Reputation: 100020

How to check if NPM cache already contains a tarball

I am looking at the cache docs: https://docs.npmjs.com/cli/cache

if I ran this:

npm cache add [email protected]

how can I check later, if this is in the npm cache?

I don't see npm cache get [email protected] in the docs...

Upvotes: 6

Views: 1861

Answers (1)

Simone Sanfratello
Simone Sanfratello

Reputation: 1610

Looks like npm has not a direct way to achieve this, but this script does the trick

create a file cache.js and paste code below

const cacache = require('cacache/en')
const cachePath = require('os').homedir()+'/.npm/_cacache'

cacache.ls(cachePath)
  .then((packages) => {
    for(const i in packages) {
      console.log(packages[i].key)
    }
  }) 

run

npm install cacache

then run

node cache.js | grep lodash

personal opinion: yarn is designed to cache npm packages, if you are going to do that, you could give it a chance

EDIT: I made a script that does all of the above, every feedback is welcome

https://www.npmjs.com/package/npm-check-cache

Upvotes: 5

Related Questions