Skip to content

Instantly share code, notes, and snippets.

@wayneseymour
Last active February 14, 2019 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wayneseymour/8f606073828401a3f905009659647977 to your computer and use it in GitHub Desktop.
Save wayneseymour/8f606073828401a3f905009659647977 to your computer and use it in GitHub Desktop.
This Dot Life | Jsinh This Dot Life
Get In Touch!
Desktop
Tools
Archive
Disclaimer
Get In Touch!
Desktop
Tools
Archive
Disclaimer
Change default NodeJS - npm and npm-cache directory on Windows
Jsinh
03 November 2016
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 C:\Users\username\AppData\Roaming\npm and C:\Users\username\AppData\Roaming\npm-cache folder.
So I wish to shift these two folders to different and custom location e.g: D:\nodejs. Let's do it!
Step:
Edit NPMRC file at follow location: C:\Program Files\nodejs\node_modules\npm\npmrc
This should be containing one like for path / prefix:
prefix=${APP_DATA}\npm
Change it to new location:
prefix=D:\nodejs\npm
Step: Edit user's NPMRC file at following location: C:\Users\usernamee\.npmrc
Replace following path fragment for all cases: C:\Users\username\AppData\Roaming with D:\nodejs
Following steps will change the default path for npm folder.
Step: Run the following command at command prompt to change the default path for npm-cache
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.
Select Path variable and click Edit
Here edit npm default location to custom path as D:\nodejs\npm
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.
Happy coding!
This is what Jsinh looks like !! Jsinh
Techy, developer, builds with .NET | C# | Xamarin | WPF | ASP.NET MVC & API. Founder at Teference. Lives with wife & kiddo. Works as consultant, poops for hour with phone & worst singer ever!
windows nodejs npm
Share337
Microsoft Specialist - Programming in C# Specialist
Bitrise Contributor @ bitrise.io
profile for Jsinh at Stack Overflow, Q&A for professional and enthusiast programmers
View Jaspalsinh Chauhan's profile on LinkedIn
Use SimpleEvents in your project
Booger stuffs to use in your WPF application. Dried, definitely repetitive, never ending and unavoidable
Disclaimer: All code, opinion and information on this blog are my personal view and do not represent or relate my past and / or current employer's view and / or business insides in any way.
Jsinh @ Facebook Jsinh @ Twitter Jsinh @ Google+ Jsinh @ Tumblr Jsinh @ Linkedin Jsinh @ YouTube Jsinh @ Skype Jsinh @ GitHub Jsinh @ RSS
This blog is Haunted with Ghost and does not look needy at all anymore.
Copyright © This Dot Life 2011-2019 • All rights reserved.
Build on top of Materialize CSS with love | Icons made by Feepik, Daniel Bruce, Linh Pham, Icomoon, Elegant Themes from Flaticon is licensed by CC BY 3.0
@wayneseymour
Copy link
Author

npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment