A PowerShell utility for Windows to run npm, yarn, or pnpm with specific Node.js versions managed by nvm. Think of it as a dynamic alias system (like in Ubuntu) for package managers, letting you easily switch between Node versions without manually typing full paths.
- Run
npm,yarn, orpnpmwith a specified Node.js version (e.g.,npmv v22 start). - Automatically picks the latest matching version if partial (e.g.,
v22usesv22.9.0if available). - Uses exact versions when specified (e.g.,
v22.7.0). - Displays the Node.js version with
--versionor-v.
- Node Version Manager (nvm) for Windows: Install from nvm-windows.
- PowerShell: Comes with Windows (any modern version works).
-
Install nvm for Windows
- Download and install
nvmfrom releases. - Verify installation:
nvm version
- Download and install
-
Install Node.js Versions
- Use
nvmto install the Node versions you need:nvm install 22.9.0 nvm install 20.11.0
- List installed versions:
nvm list
- Use
-
(Optional) Install Yarn and pnpm
- For
yarnvandpnpmvto work, install these globally for each Node version:nvm use 22.9.0 npm install -g yarn pnpm
- For
-
Add NvmAlias to PowerShell Profile
- Open your PowerShell profile:
notepad $PROFILE - If it doesn’t exist, PowerShell will prompt to create it. Confirm with
Y. - Copy and paste the script from
NvmAlias.ps1into your profile. - Save and reload your profile:
. $PROFILE
- Open your PowerShell profile:
- Install a version:
nvm install 22 - Switch versions:
nvm use 22.9.0
- List installed versions:
nvm list
NvmAlias builds on this by letting you run package managers without needing nvm use every time.
Run commands with npmv, yarnv, or pnpmv followed by a version and arguments.
- Run
npm startwith the latestv22version:npmv v22 start # Running with Node version: v22.9.0 using npm - Use an exact version:
npmv v22.7.0 install express # Running with Node version: v22.7.0 using npm
- Check Node.js version:
npmv 22 --version # Running with Node version: v22.9.0 # v22.9.0
- Run
yarn install:yarnv v22 install # Running with Node version: v22.9.0 using yarn - Check Node.js version:
yarnv v20 -v # Running with Node version: v20.11.0 # v20.11.0
-
Run
pnpm add lodash:pnpmv v22 add lodash # Running with Node version: v22.9.0 using pnpm -
Check Node.js version:
pnpmv 22.7.0 --version # Running with Node version: v22.7.0 # v22.7.0
-
Note: Omit the
vprefix if you prefer (e.g.,npmv 22works likenpmv v22).
- Version Resolution:
v22finds the latest installed version (e.g.,v22.9.0if you havev22.0.2,v22.7.0,v22.9.0).- Exact matches (e.g.,
v22.7.0) take priority.
- Package Manager: Detects
npmv,yarnv, orpnpmvand uses the corresponding tool from the Node version folder. - Path: Uses
C:\Users\<YourUser>\AppData\Roaming\nvm\<version>\<tool>.cmd.
- "No matching Node version found": Ensure the version is installed with
nvm list. - "yarn/pnpm not found": Install them globally for that Node version (e.g.,
npmv v22 install -g yarn). - Profile not loading: Verify
$PROFILEpath and reload with. $PROFILE.
MIT License - see LICENSE for details.