Install Node.js and Verify npm
npm (Node Package Manager) is included with Node.js. Download and install Node.js from its official website. After installation, verify both tools by running:
node -v
npm -v
By default, npm stores global packages and cache in the user directory (e.g., C:\Users\<User>\AppData\Roaming\npm). To relocate these directories:
Relocate Global and Cache Directories
Create two folders under your preferred Node.js installation path, such as D:\nodejs\node_global and D:\nodejs\node_cache. Then configure npm to use them:
npm config set prefix "D:\nodejs\node_global"
npm config set cache "D:\nodejs\node_cache"
Confirm the change with:
npm list -g --depth=0
Configure a Faster Registry Mirror
To speed up package downloads, especially in regions with restricted access to the default npm registry, switch to a mirror like Taobao:
npm config set registry https://registry.npmmirror.com
View current configurations using:
npm config list
These setting are saved in .npmrc located in your user home directory.
Update npm Globally
Ensure you’re using the latest version of npm:
npm install npm@latest -g
Add Global Binaries to System PATH
Add D:\nodejs\node_global to your system’s PATH environment variable so globally installed binaries (like vue, bower, etc.) can be executed from any terminal.
Install Vue.js in a Project
Navigate to your project root and initialize a package.json file if it doesn’t exist:
npm init -y
Then install Vue as a project dependency:
npm install vue --save
This adds Vue to your dependencies in package.json and downloads it into the node_modules folder.