I've installed NVM for windows, so I can switch between different versions of node when I have to. However, I have a need to be able to call one version of node / npm WITHOUT having to switch
For example, right now I have 2 versions of node installed: 10.17.0 and 8.9.1. I can easily switch between them using nvm use 10.17.0
or nvm use 8.9.4
, and after either of those commands, when I run node ./app.js
or npm install package
, it uses the expected version of node / npm to do what I'm asking
But I want to create a situation where I can avoid switching, and instead I can just type node10 ./app.js
or npm10 install package
, and it uses the version I specify
Now, I've done a bit of research myself about what it would take to do this, so I'll lay that out and hope that someone has some advice because they've done something similar.
First of all: nvm installs both versions of node in a specific place, and that place should stay static and unchanging. I can find the 8.9.1 versions of node and npm here: C:\Users\SamuelR\AppData\Roaming\nvm\v8.9.1
I can find the 10.17.0 versions here: C:\Users\SamuelR\AppData\Roaming\nvm\v10.17.0
When I use nvm use 10.17.0
, what it does is it changes a symlink at C:\Program Files\nodejs
, and it points it to whichver of those two folders I specify
So my idea to make node8 / node10
and npm8 / npm10
commands work was this:
In some folder in my PATH, I was going to create 4 .bat files, node8.bat npm8.bat node10.bat npm10.bat
. For node8.bat
, I was going to follow the example here:
C:\Users\SamuelR\AppData\Roaming\nvm\v8.9.1\node.exe %*
, so that it always forwards all my command line arguments to the correct installation.
For npm, the file npm8.bat
would have C:\Users\SamuelR\AppData\Roaming\nvm\v8.9.1\npm.cmd %*
.
Maybe I'd do the same for npx. And then I'd repeat those steps for the node10.bat npm10.bat
files.
Is this the right way to go about this? Does it even make sense?