Developers mostly like to take control of your machine and how things work on it. This time I decided to take control where NodeJS would restore my global packages and manages package cache.
In this case I am referring to Windows 10 particularly as that is my core development platform.
By default NodeJS gets installed in
C:\Program Files\nodejs folder (assuming you are installing nodejs - Windows x64 version).
After installation lets say I wish to install
http-server package so I can run static HTTP server from any folder.
As soon as I do
npm install http-server -g, this start adding package and it's dependency packages into
So I wish to shift these two folders to different and custom location e.g:
D:\nodejs. Let's do it!
Edit NPMRC file at follow location:
This should be containing one like for path / prefix:
Change it to new location:
Step: Edit user's NPMRC file at following location:
Replace following path fragment for all cases:
Following steps will change the default path for
Step: Run the following command at command prompt to change the default path for
npm config set cache D:\nodejs\npm-cache --global
Step: Change the path for npm set at user environment variable level.
Open Environment variable edit dialog: Right click on Windows icon > System > Advanced system settings > Environment Variables > Top section "User variables for username.
Path variable and click
Here edit npm default location to custom path as
That's it, next time when you run
npm install anything -g it would restore those packages and setup npm cache at your custom location.