Just before the start of my weekend, I got a message from one of our administrators, the disk space on one of our build servers was filling up. Whoops!
Yesterday I explained that a part of the disk consumption could be explained by the global packages folder of NuGet. But if you take a second look at the screenshot I shared, you certainly notice that the AppData folder also needs some attention:
Let’s further drill into this folder and well’ notice another culprit; the npm-cache folder!
What is the npm-cache folder?
The npm-cache
folder serves as a local cache where NPM stores downloaded packages and their dependencies. When you install a package using NPM, it first checks if the package is already in the cache. If so, it avoids re-downloading it, which speeds up subsequent installations.
This cache helps reduce network requests and ensures that packages are readily available for future use.
On Windows, the default path for the NPM cache is %AppData%/npm-cache
or %LocalAppData%/npm-cache
.
On macOS and Linux, the default cache location is ~/.npm
, which translates to /home/YOUR_USER/.npm
.
How to change the npm cache location?
You can change the cache folder by using the NPM command line:
npm config set cache D:\\npm-cache --global
After running this command, you can verify the cache using:
npm --global cache verify
Remark: You also see another NuGet folder in the screenshot. This is the http cache folder of NuGet where the Visual Studio Package Manager and the dotnet
tool store copies of downloaded packages in this cache. Packages are not expanded, and the cache has an expiration time of 30 minutes.