npm-cache
Manages the npm package cache
TLDR
Add a specific package to the cache
Remove a specific package from the cache
Clear a specific cached item by key
Clear the entire npm cache
List the contents of the npm cache
Verify the integrity of the npm cache
Show the cache path
Change the cache path
SYNOPSIS
npm cache clean [--force]
npm cache verify
PARAMETERS
clean
Removes all data from the npm cache.
--force
When used with `clean`, bypasses confirmation prompts and forcefully removes the cache. Use with caution!
verify
Verifies the integrity of the cache, ensuring that cached data is not corrupted.
DESCRIPTION
The `npm cache` command is used to manage the local npm package cache. This cache stores downloaded packages to avoid redundant downloads when installing or updating dependencies. Managing the cache can free up disk space, resolve installation issues caused by corrupted cache data, and ensure that you're using the correct versions of packages. Commands like `npm cache clean` remove all cached data or specific packages, while `npm cache verify` checks the integrity of the cache. The npm cache is crucial for offline installations and significantly speeds up package installations by reusing previously downloaded packages. Understanding how to use `npm cache` is vital for optimizing your npm workflow and troubleshooting package installation problems. Properly managing the cache can prevent errors caused by outdated or corrupted data, ensuring your projects consistently use the desired package versions.
CAVEATS
The `npm cache` is located by default in a platform-specific directory, but the location can be modified using the cache
configuration option in npmrc. Always be careful when using npm cache clean --force
, as it removes everything from the cache, potentially slowing down future installations if network conditions are poor.
CACHE LOCATION
The default cache location depends on the operating system. You can find the current cache location using npm config get cache
. It can be changed by setting the cache
configuration option with npm config set cache /path/to/new/cache
.
TROUBLESHOOTING INSTALLATION ISSUES
If you encounter issues installing packages, running npm cache clean --force
followed by npm install
can often resolve problems caused by a corrupted or outdated cache.
HISTORY
The `npm cache` command has been a core part of npm since its early versions, evolving alongside the npm ecosystem. Initially focused on basic caching functionality to reduce download times, it later incorporated features like verification to enhance reliability. Over time, the command has been refined to address common user issues, such as disk space management and cache corruption, leading to its current set of functionalities. Its development mirrors the growing complexity and sophistication of Node.js package management.