node.jsnpm

How can I change the cache path for npm (or completely disable the cache) on Windows?


I've installed Node.js on my Windows 7 x64 development machine, the manual way:

mkdir C:\Devel\nodejs
cd C:\Devel\nodejs
set NODE_PATH=%CD%
setx /M PATH "%PATH%;%NODE_PATH%"
setx /M NODE_PATH "%NODE_PATH%\node_modules"

I've placed the main node x64 binary along with npm package manager in C:\Devel\nodejs. Works like a charm and I can update the main binary without dealing with the installer.

The only problem I can't solve is moving the cache folder. When I install a local package:

npm install express

... cache is placed under %APP_DATA%\npm-cache folder. I'd like to change it to:

C:\Devel\nodejs\npm-cache

How can I change the npm cache folder, or disable it completely?


Solution

  • You can change npm cache folder using the npm command line. (see https://docs.npmjs.com/cli/v6/using-npm/config#cache)

    So you might want to try this command :

    > npm config set cache C:\Devel\nodejs\npm-cache --global 
    

    Then, as commented by smac89:

    run npm --global cache verify after running this command.