How to check Node version for a specific project? - node.js

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

Related

The engine "node" is incompatible with this module. Expected version "7.5.0". Got "15.13.0"

one of my friends sent me a project using react and node and i tried to run it with yarn. Each time i run this command i got this error : The engine "node" is incompatible with this module. Expected version "7.5.0". Got "15.13.0". I just want to know how update the react version of a project
Have a good day
You can change your package.json
"engines": { "node": ">=7.5.0"},
This will make the projects run with node 7.5.0 or newer versions. Also using nvm
nvm install version_you_want
nvm use version_you_want
Check node and npm versions
node -v
npm -v
Other option is to use
yarn install --ignore-engines
See this post: How to fix engine "node" version?
In my case I was gettin the same error because I didn't set the .env file
You could use this npm package, but be aware of breaking changes especially as it seems to be a very old version.
A better approach may be to use nvm - node version manager (or nvm-windows if that is your operating system) to install and use an older - compatible version of node, e.g. v7.5.0.

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

Different versions of node on the same computer

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.

Use specific Node version in combination with specific npm version

For a client's web project I work with two other developers. The frontend is built with quite a setup (gulp, foundation, bower, ...) and started a few years ago. They both use a (never updated)
combination of Node v6.12.2 and npm v5.6.0.
As I had Node v10.x on my machine and the first attempts of running npm install after cloning the project failed, I'd like to use the exact same setup:
I setup nvm to use v6.12.2
$ \projectfolder nvm use v6.12.2
The Terminal then states:
Now using node v6.12.2 (npm v3.10.10)
How can I tell my setup to use npm#5.6.0 along with node v6.12.2? I tried npm install npm#5.6.0 which then changes the used npm version, but also changes the used node version back.
I know nvm installs the respective npm version along with the node version. But is there a way to work with exactly this combination of versions the other developers use in my project?
After switching node versions with nvm use (and confirming you switched with node --version), you should globally update/downgrade npm with:
npm install -g npm#5.6.0 // -g arg is important
Switch back to other node version and it should be using its own version. Also see this npm article about installing npm versions.
If you want to know why it is installed globally: run in the command line:
ls -l $(which npm)
It returns
/home/USER_NAME/.nvm/versions/node/vNODE_VERSION/bin/npm -> ../lib/node_modules/npm/bin/npm-cli.js
It's a symlink to the global node_modules folder of that specific node version.
Find where your nvm is installed .eg:
Then you can explicitly call your desired npm version like:
your\path\..\AppData\Roaming\nvm\v12.10.0\npm -help

Running local node verison different than global with gulp and node-sass

I have a project that is using node npm and gulp. When we build the project node 5 is installed in the local directory and runs npm install (compiling all node modules agains node v5) I globally have node version 7 installed.
We have a gulp task that uses node-sass which is compiled against v5 but when I try to run the task it uses the global version and node-sass errors out out "Missing binding"
How can I run it using the local version of node?
nvm is very helpful for managing and switching between multiple versions of node, including your globally installed packages.
If you are looking to automate it, you could just add the console command to use the needed version via nvm within your gulp task.
e.g. "nvm install v5.0.0"
To expand upon #dmfay's answer, you should have node 5 installed (via nvm or tj's n).
However you can include in your package.json for the project such that it relies on node 5. (Under the "engine" property)
None of the install/rebuild solutions resolved the issue for me (using gulp).
Here is how I resolved it:
1) Download the missing binding file from the repository.
2) Rename the file binding.node.
3) Create /node-modules/vendor/<operating system>/ (for my version of node/node-sass the <operating system> directory for linux is linux-x64-64, use folder name from missing binding error message)
4) Add binding.node file to /node-modules/vendor/<operating system>/.
5) run gulp

Resources