npm (Node Package Manager) is a package manager for the JavaScript runtime environment Node.js. npm enables developers to share and reuse code, automate tasks, and manage project dependencies.
Verify cache
The verify
command is primarily used for checking and optimizing the npm cache. npm
verifies the integrity of all files in the cache. If any files are found to be corrupt, they are removed.
npm cache verify
npm cache verify
removes unnecessary files from the cache, such as old or duplicate packages. It rebuilds the cache index to ensure that it is accurate and efficient, and provides a summary of the performed operations. This summary includes which files were checked, which files were found to be unnecessary and removed, and which issues were fixed during the process. After running npm cache verify
, you might notice a reduction in the cache size.
Clean cache
The clean
command is useful when you want to completely reset the npm
cache, for example, if you suspect the cache is causing issues or if you want to free up disk space. After running this command, npm will need to fetch all packages from the registry again, which might slow down subsequent installations temporarily.
npm cache clean
Output
npm ERR! As of npm@5, the npm cache self-heals from corruption issues
npm ERR! by treating integrity mismatches as cache misses. As a result,
npm ERR! data extracted from the cache is guaranteed to be valid. If you
npm ERR! want to make sure everything is consistent, use `npm cache verify`
npm ERR! instead. Deleting the cache can only make npm go slower, and is
npm ERR! not likely to correct any problems you may be encountering!
npm ERR!
npm ERR! On the other hand, if you're debugging an issue with the installer,
npm ERR! or race conditions that depend on the timing of writing to an empty
npm ERR! cache, you can use `npm install --cache /tmp/empty-cache` to use a
npm ERR! temporary cache instead of nuking the actual one.
npm ERR!
npm ERR! If you're sure you want to delete the entire cache, rerun this command
npm ERR! with --force.
To clear the npm cache, use the --force
flag. The --force
flag is necessary because npm doesn’t recommend clearing the cache without a good reason, but it allows you to bypass the warning.
npm cache clean --force
The -f
or --force
flag is required because this command is destructive and will remove the entire cache, which could potentially affect subsequent npm
operations until the cache is rebuilt. Use this when you need to completely clear the cache, such as when troubleshooting cache-related issues or freeing up disk space.