Unfortunately nvm use on Windows does not change the node version to that specified in the `.nvmrc` file as its not supported on nvm for Windows.
So the easiest solution to this is to create a simple Powershell command that performs an approximation of the command which is to switch to the version specified and, if it doesn’t already exist, download and install it first:
nvm use $(Get-Content .nvmrc).replace( 'v', '' );
However, thats a bit awkward and we can do a bit more so instead, we can create an ‘alias’ to a function that calls the command instead:
function callnvm() {
$versionDesired = $(Get-Content .nvmrc).replace( 'v', '' );
$response = nvm use $versionDesired;
if ($response -match 'is not installed') {
if ($response -match '64-bit') {
nvm install $versionDesired x64
} else {
nvm install $versionDesired x86
}
nvm use $versionDesired;
}
}
Set-Alias nvmu -value "callnvm"
Now we only need to type nvmu in a project folder for it to work properly.
However, this will only work for the current session, so to make it more useful for any project and every session; we can add this content to the Powershell Profile for the current user.
You can get the location of this file by typing $profile in a Powershell session and either edit or create the Profile file and place the content shown above into it.