Different versions of node on the same computer - node.js

I am working on two different angular projects on my computer.
If I run node -v on project A's root folder I get version 10.15.3 and if I run node -v on project B's root folder I get another version 12.1.
I don't understand why node is showing two different versions.
If I check the PATH of the node command it points to the same file /usr/bin/node.

thanks for replaying back. I am not using nvm. However I was checking another question here: link
node -v v10.15.3
nodejs -v v12.1.0
node comes from apt-get installed package (on Debian).
I was having issues when serving an ionic app, so I decided to remove npm version of node (v12.1.0):
npm remove -g node
Then I open another terminal and now node and nodejs are showing same version 10.15.3. For my testing purposes I need LTS version instead of latest in order to ensure less bug-prone code.

Related

How to check Node version for a specific project?

I have Node version 16.13.1 installed globally in my machine. I have a project where I want to downgrade the version to 14.19.1. I used the command npm install node#14.19.1 --save-exact to downgrade, and this version is reflecting in my package.json file.
The problem is, when I run node -v at my project's root folder, the version is returned as 16.13.1. To check this, I made an entry in scripts in package.json - "v": "node -v". When I run npm run v, the output is 14.19.1.
It's clear that my project's Node version was downgraded successfully. So, why does Node show me the global version when I check it from my project's folder? Is there flag to use with node -v to check the local version?
To use multiple node versions in your system you have to use nvm. Which is useful to install multiple node versions and easy to switch node versions as per project requirements. NVM Installation Guid

checking version of node on macOs

I wanted to check the version of node js on my machine. It gives two different numbers:
/usr/local/n/versions/node$ ls
14.16.1
/usr/local/n/versions/node$ node -v
v8.9.4
Are there two different versions?
We can have different nodejs versions on the same machine, but there is only 1 active version for a user at the same time.
Your command node -v give you the NodeJS active version, which is v8.9.4.
The ls command give you only the content of the folder. NodeJS v14.16.1 is installed on your machine, but is not active.

NG command is displaying incorrect node version

I am getting below error when I tried to use ng command
Node.js version v11.13.0 detected.
The Angular CLI requires a minimum Node.js version of either v10.13 or v12.0.
Please update your Node.js version or visit https://nodejs.org/ for additional instructions.
When I try to see the node version using node -v, I see node version on my machine is v12.18.3
So from where ng is getting v11.13.0? How do I resolve this issue?
I tried below steps
Clear the NPM cache
Uninstall both node versions from the NVM
Uninstall anything that starts with node in Control Panel\Programs and Features
Install required node versions in NVM
Install Angular CLI
and things started working for me.
Had the same issue. It turns out installed Angular CLI was not compatible with the installed node and npm version. I used the https://stackoverflow.com/a/60258560 to check the compatibility. Then performed following steps:
Uninstall Angular cli
Uninstall Node and NVM
Installed Node version I wanted (10.x).
Installed specific Angular version corresponding to Node v10 which was Angular Cli v11 at this time.
I was also facing the same issue in my Windows machine where the node -v version and the version picked up by ng command were different. This was because my node.js command prompt was picking the version from AppData\Roaming\npm folder. Cleaning up this folder fixed the issue for me.
Uninstall node
Empty the contents from C:\Users<user>\AppData\Roaming\npm
Install the required node version

Which node version will be use as default?

In my Linux mint, previous version of nodejs was v8.10.0 so I decided to upgrade it and after upgrade, I run nodejs -v but it is sill reporting v8.10.0 (after restarting pc too). If I run node -v it is reporting v12.17.0 (which is currently the latest version). I don't know what is the difference between node and nodejs.
I run a xyz.js file from both node and nodejs it runs successfuly.
You can see some terminal output for your help -
$ which -a node
/usr/local/bin/node
/usr/bin/node
$ node -v
v12.17.0
$ which -a nodejs
/usr/bin/nodejs
$ nodejs -v
v8.10.0
Is my system using node/nodejs latest version, If not what should I do ?
What's happening here is simply the new version of node installs as 'node' while the older version installed as 'nodejs'. Given that your older version of 'nodejs' was working fine and the new version, 'node', never overwrote it you're left with two different versions of node. As a test, I change the name of the node file and or remove it from the folder altogether and see what happens. I'm sure you will be left with only on the version of node being recognized on your system.

How Can Knex (or Any NPM Package) Run a Different Version of Node?

I'm trying to use Knex's seed:run command (ie. npx knex seed:run), and inside my seed file I've added this line, which logs the version of Node that it's being run with:
console.log(process.version);
Now, if I run that exact same line of code in the Node command prompt itself (node), I get:
v14.2.0
Similarly, when I run node --version it correctly returns v14.2.0.
However, when Knex runs my seed file, I instead see:
v11.15.0
Can anyone explain how/why Knex is using a different version of Node, and how I can make it stop?
P.S. I've tried wiping my node_modules folder out and re-installing via npm i, but Knex continues to use an old Node somehow. Knex itself is installed at the latest version (0.21.1).
This may happen if you have a global installation that runs in privileged account (root), and a local installation to current user.
It is possible you are using some node versioning tool to manage nodejs versions, it creates a symbolic link to a managed version of node that overrides the default configuration. There are many tools that does that like nvm, n.
Danizavtz's answer didn't solve thigns for me, but it did point me in the right direction. I realized that I did have two versions of Node: one installed by Linux (using apt-get), and one I'd installed myself (to get a newer version of Node).
The solution for me was to remove the system version of Node with:
sudo apt-get remove node
That left me with a working Node ... but it removed my npm. I guess I could have just re-installed everything, but since I already had node and just needed npm, I downloaded the latest Node installation and used the node in it to install npm. I did this both with and without sudo (I'm not sure if doing it without sudo was even necessary, as it didn't fix things):
sudo ~/node-v14.3.0-linux-x64/bin/node ~/node-v14.3.0-linux-x64/bin/npm i -g npm
After that I finally got the expected Node version when I ran npx/npm!

Resources