Which directory gets cleared by npm cache clean command?

I’m trying to understand what happens when I run npm cache clean --force on my system. The documentation says it should clear the cache directory, but I’m confused about the actual behavior.

When I look at my ~/.npm folder before running the command and then check it again after the cleaning process finishes, all the files and folders appear to be identical. Nothing seems to have been removed or modified.

This leaves me with a couple of questions:

  1. What specific directory does npm actually target when executing this cache clearing command?
  2. What exactly is stored in the ~/.npm directory and what purpose does it serve?

I expected to see some changes in the file structure or at least some reduction in folder size, but that didn’t happen. Any clarification would be helpful.

The npm cache clean --force command only cleans the _cacache subdirectory inside your npm cache folder - it doesn’t touch the entire ~/.npm directory. That’s why you’re not seeing changes at the top level. Your ~/.npm folder holds registry info, logs, and the package cache, but the cleaning only hits the cached package data in _cacache. Check that subdirectory before and after running the command - you’ll see the difference there. The cache location varies by system, so run npm config get cache to see your exact path. Sometimes it looks unchanged because the cache was already empty or npm quickly repopulated it with common packages.

It seems there is a common misunderstanding regarding the cache location. On Windows systems, for instance, the npm cache is often found in %APPDATA%/npm-cache, rather than in ~/.npm. This can lead to confusion, as the ~/.npm directory primarily contains configuration files and logs. When you execute the npm cache clean --force command, it targets the specific cache storage, which may not be visible in your ~/.npm folder. To confirm the clean operation’s effectiveness, consider checking your temporary directories or running npm cache verify post-command.

true, the cache clean doesn’t clean your whole ~/.npm folder, just the package cache. Try running npm cache verify to gauge whats left. Also, when you install stuff, it often rebuilds super fast, making it seem like nothin’s changed.