Select Page
This entry has been published on 2018-08-14 and may be out of date.

Last Updated on 2018-08-14.

[:en]Starting e.g.an Angular project using Visual Studio and Node.js, NPM will fill the user’s AppData directory with thousands of files.

Depending on your Windows domain network structure, the AppData folder might have been configured to be redirected to a central server using group policies and the folder redirection feature (and/or server-sided user profiles). So because of the permanent r/w network access to those directories, every Node.js processing becomes very slow and buggy.

In addition, you might run into troubles if the user works with default (non-admin) permissions. Global packages have to be installed with admin rights by default, which leads to several issues because of the different user names, profile directories etc.

Workaround

My basic suggestions for a working Node.js system in a multi-user domain environment:

  • Do not ever install NPM packages as admin user!
  • Instead, create a separate nodejs folder where the global packages can be installed with user permissions
  • Move and redirect all Node.js’ user folders to a local directory.

Steps

You might want to start uninstalling Node.js in general and also remove existing folders manually:

  • %programfiles%\nodejs
  • %programfiles(x86)%\nodejs
  • %appdata%\npm
  • %appdata%\npm-cache

Then install the current LTS version of Node.js using the .exe or .msi package.

For Node’s global files which should be able to be installed with user permissions, I use a separate folder f:\nodejs in this example. Of course, you can also place this folder e.g. on c:\nodejs.

Open CMD window with elevated permissions and enter:

npm config set prefix f:\nodejs --global
npm config set cache f:\nodejs\npm-cache --global

Then do the same in a CMD window with default permissions.

To be safe, add some folder redirections (NPM’s config is not always considered for unknown reason):

mklink /d "c:\program files\npm\etc" f:\nodejs\etc
mklink /d "%appdata%\npm-cache" f:\nodejs\npm-cache

Edit the user’s PATH environment variable to also match the new nodejs directory:

Re-check if the paths really changed to f:\nodejs:

npm config list

You can also check Node’s config files, like %appdata%\npm\etc\npmrc and %programfiles%\nodejs\etc

Then try to install a test package using “npm install”. If you add the “-g” parameter, it should be installed in f:\nodejs\node_modules; otherwise in your project’s folder as usual.

Optional: If you use Visual Studio, you might want to change the setting to use the Node.js version you installed separately, and not the one included in VS, as it could maybe use other versions and config files. Open VS settings -> Web Package Management -> External Web Tools. It could look like this (German):

 [:]