Change Packages Paths in NodeJS
1 min read

Change Packages Paths in NodeJS

Change Packages Paths in NodeJS

TL;DR: Edit %appdata%\npm\etc\npmrc and add prefix and cache entries to specify the locations where node puts packages.

Every time I install a new framework/dev environment I have to look where they put files. Having a roaming profile is a pain and I need to make sure it doesn't get too crowded. Otherwise, logging in takes 30+ minutes.

The latest victim is NodeJS. This installs a lot of files for all packages in 2 directories (I found so far):

  • Cache - a cache of installed modules
  • Global - a place where it places all install -g modules and their dependencies

By default, both are in your roaming profile and you easily end up with 300Mb of small files. To move them, you need to:

  • Go to %appdata%\npm\etc
  • Edit npmrc with:
prefix=(directory with global installed packages)
cache=(directory with cached packages)
  • Save the file and remove the already installed modules.
  • Reinstall your favourite modules.