11

Is it possible to change where you install your dependencies when doing npm install -g module? I know it installed in your C:/../{name}/Appdata..etc but I want to change the path on mine due to limited disk space.

I've installed node.js on an external disk which is fine and can do npm commands, but now I want the global dependencies to be installed on this disk as well.

Is there a way to do it?

MrNew
  • 1,384
  • 4
  • 21
  • 43
  • Possible duplicate of [Change default global installation directory for node.js modules in Windows?](http://stackoverflow.com/questions/19874582/change-default-global-installation-directory-for-node-js-modules-in-windows) – Sami Dec 16 '16 at 10:01

2 Answers2

17

You can configure it to new PATH by the following command -

npm config set prefix '~/.npm-new-global'
swapnesh
  • 26,318
  • 22
  • 94
  • 126
  • Thanks, I've installed angular-cli after this and its not giving the the command `ng`. Not sure if this is related to this. – MrNew Dec 16 '16 at 10:33
  • 1
    Solved it now, I've added the angular-cli path in the environment path – MrNew Dec 16 '16 at 10:45
1

You can also use the environment variable NPM_CONFIG_USERCONFIG to set a new local for your config file, that is, npmrc. For instance, you can add to you login config file (~/.profile) the following line

export NPM_CONFIG_USERCONFIG="$HOME/.config/npm/npmrc"

Then, on the file ~/.config/npm/npmrc you can write

cache=~/.cache/npm
prefix=$~/.local/share/npm

Here, the advantage is that you have set both the ~/.npm and its cache to match with the XDG Base Directory Specification

reference

Rubem Pacelli
  • 332
  • 2
  • 12