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:
- You may change the installation directory.
- 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:
-
Create two directories within your Node.js installation folder:
node_globalandnode_cache. -
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" -
Update environment variables:
- Add a new variable named
NODE_HOMEwith the value of your Node.js installation path. - Modify the
PATHvariable to include the following antries:%NODE_HOME%%NODE_HOME%\node_modules\npm\bin
- Add a new variable named
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
-
Install
nrm, a tool for managing npm registries:npm install nrm -g -
List available registries:
nrm ls -
Switch to the Taobao registry:
nrm use taobao -
Test performance:
nrm test npm
This should significantly improve download speeds.
Troubleshooting
If npm install fails, consider upgrading your Node.js version.