Mismatch between node version in console vs node version in process.version? - node.js

I have NVM to manage node versions, and I need to use 6.10 for a current project.
When I node -v in terminal I get, v6.10.3. When I run nvm alias default I get default -> 6.10 (-> v6.10.3). In my IDE, Webstorm, I have my Node interpreter set to 6.10.3, and in my package.json I have:
"engines":{"node":"6.10.3"}
However, in my project itself when I run
console.log(process.version);
I get v4.3.2. What am I doing wrong? How can I switch to 6.10.3 in my actual project?
Thanks!

(nvm maintainer here)
The engines field in package.json is purely advisory, and nvm does not pay attention to it. You can add an .nvmrc file to your project with your desired version number; however, you’ll still need to manually nvm use to activate it (see the project readme for ways to make it auto-use on cd, which is too intrusive to do by default).

Related

How can I choose node version for ng build command?

I have two different version of node version installed - 11.6 and 13.6. 13.6v is set in path variable so that is default node. I have a project which needs to be built only using 11.6v. But my ng command is using node 13.6 by default (I checked this using ng --version). Is there anyway I can ask ng to use node from a specific folder where I have 11.6 installed instead of the default one.
Edit: This is on Jenkins VM, so I don't have much access to change things.
I think the easiest way to work with different versions is using nvm tool.
See:
https://github.com/nvm-sh/nvm

Set node version differently for specific project(folder) via NVM

I know I can change the node version by nvm use CLI command. However, I want to set specific node version differently for a certain project(folder). It's changed via nvm use command but it's reverted to default version whenever I restart the terminal or webstorm IDE.
How can I set nvm remember this different version for a certain project(folder)?
You can use an .nvmrc file in the root of the project with the version you want to use. For example v12.4.0 or v10.16.0.
You have to make sure that this version is installed or it will use the default node version in your machine.
For example, you want your default node version for this project to be v12.
Open your command line in the project root folder, then run nvm use 12, then run node -v > .nvmrc.
It won't solve your issue completely because you'll anyway have to run nvm use just without the version.

Why do I need to uninstall node from my computer to use nvm?

I recently decided to install nvm, and the instructions had me uninstall node. I noticed that if I explicitly tell nvm to use a certain version it uses it from the nvm directory, otherwise it uses my bin/node directory, so I didn't notice a conflict. When I uninstalled node, i needed to specify a version every time I use my terminal which seems like an unnecessary step when I could just leave node installed via brew and use nvm if I need to version control.
Once you install nvm and use Node through it, it does NOT use bin/node, but the version installed with nvm, so your old Node is obsolete.
The main reason they recommend you to uninstall Node is because it could confuse the shell about which Node to use. Of course, you can update your shell config so that it first looks for Node installed from nvm, but that's an unnecessary extra step and your old Node distribution is obsolete on your disk, at best.
So, the best solution is uninstalling the old distribution and install nvm (which by default installs the latest Node in your .nvm folder), and install more versions of Node if necessary.
And regarding this:
i needed to specify a version every time I use my terminal which seems like an unnecessary step
You don't need to, as long as you set the default version (say, 11.15.0) config after installing nvm with the following command:
nvm alias default 11.15.0

NVM doesn't switch the expected Node.js version

I want to use an older version of Node.js in my application, and for that I have attempted to use nvm so that I can change the version accordingly.
Now I have three versions of Node.js and want to switch on specific version
nvm use [selected version]
It is successfully executed but the version is not updated
Example of use:
If your nvm command not updating your node version in windows, for example
Your current version is 6.11.2 and you would like to update to 8.11.3 using nvm use 8.11.3 in windows OS then below hack will do that job.
Renamed C:\Program Files\nodejs to C:\Program Files\nodejsx it worked for me.
Credit goes to user ituasdu
From the readme of NVM, under important notes:
Note: nvm does not support Windows (see #284). Two alternatives exist, which are neither supported nor developed by us:
nvm-windows
nodist

I installed node.js v5.12.0 but the version showing v0.12.2

I installed Node.js from (https://nodejs.org/dist/latest-v5.x/node-v5.12.0-x64.msi), but the issue is , its showing version v0.12.2 instead of v5.12.0 which is required.
I try to update the node.js 5.2 installer but still showing version v0.12.2.
I have uninstalled Node.js and reinstall node-v5.12.0-x64.msi but still it’s not updated. Due to this am not able to run further commands for Ionic environmental setup.
Open a terminal and type where node
It should point to an old version of node (v0.12.2) still installed on your computer, for example C:\bin\node.
As Node.js is portable, you can have multiple versions on your computer.
If it cannot be uninstalled, simply delete C:\bin\node folder.
Then:
Open Windows System Properties/Advanced system properties
Click on Environment variables and edit PATH variable
Remove inside its value the path of the old version of node (C:\bin\node in our example).
Re-install Node v5.
Close your terminal and open a new one then type where node, it should point to Node.js v5
Most likely, you have an old Node version for x86 platform, and you are installing a newer version for 64 bit. Remove the path to the x86 from the Paths env variable, or move it to after the 64 bit path.
Solution:
List node.js installatios using nvm:
nvm ls
High chance the version you tried to install is also listed
Select the version to use using nvm
nvm use
(Not a direct solution)
You can try to install using nvm
Uninstall nodejs and follow the instruction from https://github.com/coreybutler/nvm-windows

Resources