Change default global installation directory for node.js on Windows


Change the default global location for installation of npm packages, cache etc.

- March 16, 2019

Rest of the Story:

Within companies often Anti-Virus (AV) can impact the installation process of common/recent npm modules.  EPERM errors can occur during the npm -g installation process indicating that there are conflicts between the AV scanning process and the installation. 

The default location for node modules has generally been a sensitive directory for AV software %appdata% and can be locked down.  Node Installation

Node will install itself to this directory on your Windows PC C:\Program Files\nodejs\node_modules\npm

Following path will be added to the PATH variable C:\Program Files\nodejs\

Within this directory is a npmrc file with the following PREFIX default prefix=${APPDATA}\npm Changing the default location of node_modules

You can determine the current node default directory by executing npm config get prefix (you can run this after your following update)

Open the npmrc file located in C:\Program Files\nodejs directory.

Default value prefix=${APPDATA}\npm  which converts to C:\Users{username}\AppData\Roaming\npm directory.

Change the prefix value to your new custom location i.e. prefix=c:\npm * ALSO –>

Change the existing PATH variable from c:\Users{username}\AppData\Roaming\npm to c:\npm (Right click on This PC, Advanced Tab, Environment Variables, Select Path in the list and Edit, find the existing npm path and change it)

Alternative to changing the npmrc file manually

npm config set prefix c:\npm
npm config set cache c:\npm-cache
Windows System Path can be edited via RapidEE