This script was written for my own use but can be freely be used by others. While bugs reports are welcome, this was not meant to be heavily shared and maintain for wide audiance.
A PowerShell script using nvm-windows to update node version based on .nvmrc
file available.
Like nvm-sh, it will traverse directory structure upwards from the current directory looking for the .nvmrc
file, then edfault to the one in your profile directory if any.
When working on several different Node projects, potentially using different Node version, it can be annoying to easily switch from one version to another and mostly to the correct one.
That what the .nvmrc
file is basically for.
The author of [nvm-windows] decided not to support such feature and clearly explained where this decision comes from and future alternative is working on.
Meanwhile, I created a simple script to allow such desired behavior for myself. Especially since I often switch from Windows to WSL environent, with the latter supporting the .nvmrc
file existing in my projects.
This is meant to be use in a PowerShell 7 terminal and not a Command Prompt.
Put the script file in the directory when nvm-window exist (run echo $env:NVM_HOME
if not sure).
If you have been using nvm
, you should be able to access the script from CLI since you are more likely added the directory to your PATH
variable.
Then simply run Update-Node-Version
from your working directory and it should update your Node version using nvm
accordingly.
On Unix I run nvm install
instead of nvm use
as it allows to install the missing version when necessary, then switch to it.
If already installed, it simply skip the install, and still switch to the version.
To pair with this usage, this script will run in a similar fashion.
While 'lts', 'latest', and 'newest' has been tested, I'm not actively using it.