Installing Node.js, Managing Global Module Paths, and Switching npm Registry Sources

Installation Process

Downloading Node.js

Visit the official website at https://nodejs.org/en/download/ to download the appropriate version for your operating system.

Installing Node.js

The installation process is mostly default settings. However, pay attention to these two options:

  1. You may change the installation directory.
  2. Choose to automatically install required tools such as Python, C/C++ build tools, and Chocolatey (recommended). If you prefer to manage these manually, ensure Python is already installed to avoid duplicate installations.

Verifying Installation

Open a terminal and run the following commands:

node -v
npm -v

A successful installation will display version numbers. If no output appears, refer to troubleshooting steps.

Configuring Global Package and Cache Directories

By default, global packages are installed into C:\Users\username\AppData\Roaming\npm and cache files are stored in npm_cache, which can clutter the C drive. To customize these paths:

  1. Create two directories within your Node.js installation folder: node_global and node_cache.

  2. Set custom paths using npm configuration commands:

    npm config set prefix "D:\software\work\nodejs\node_global"
    npm config set cache "D:\software\work\nodejs\node_cache"
    
  3. Update environment variables:

    • Add a new variable named NODE_HOME with the value of your Node.js installation path.
    • Modify the PATH variable to include the following antries:
      • %NODE_HOME%
      • %NODE_HOME%\node_modules\npm\bin

Switching npm Registry Sources

Since the default npm registry is hosted overseas, downloads may be slow. Two approaches are available:

Option 1: Using cnpm

Install the Taobao mirror version of npm:

npm install cnpm -g --registry=https://registry.npm.taobao.org

Option 2: Using nrm

  1. Install nrm, a tool for managing npm registries:

    npm install nrm -g
    
  2. List available registries:

    nrm ls
    
  3. Switch to the Taobao registry:

    nrm use taobao
    
  4. Test performance:

    nrm test npm
    

This should significantly improve download speeds.

Troubleshooting

If npm install fails, consider upgrading your Node.js version.

Tags: nodejs npm installation configuration Registry

Posted on Wed, 14 Oct 2026 16:43:50 +0000 by ulrikqk