{

Multiple ways to get NodeJS version with examples


Multiple ways to get NodeJS version with examples with examples

This tutorial shows multiple ways to know the installed node and npm version.

How to get Node and npm versions in the command line.

Open terminal, type below command node --version or node -v

C:\>node --version
v14.17.0

node –version gives nodejs version installation number.

If you got the below error, node: command not found without a print version number, Then the probable cause is nodejs is installed correct version or node path is not correctly set in environment variables.

-bash: node: command not found

And,npm is a node package manager that installs automatically with nodejs installation Run the below command to get the npm version.

C:\>npm --version
7.11.1
C:\>npm -v
7.11.1

Another way is to get the node version in javascript programming.

A process is a global object in Nodejs, versions property returns an object of versions

Create a main.js

console.log(process.versions)

Running node main.js output below versions It contains node attribute with version

{
  node: '14.17.0',
  v8: '8.4.371.23-node.63',
  uv: '1.41.0',
  zlib: '1.2.11',
  brotli: '1.0.9',
  ares: '1.17.1',
  modules: '83',
  nghttp2: '1.42.0',
  napi: '8',
  llhttp: '2.1.3',
  openssl: '1.1.1k',
  cldr: '38.1',
  icu: '68.2',
  tz: '2020d',
  unicode: '13.0'
}

Another property process.version gives node version

console.log(process.versions)

Similarly, you can get the node version using the command line with REPL. REPL is Read-Eval-Print-Loop interactive terminal to get nodejs process and execute node commands

Type node in terminal to change to REPL mode

node

Type process.versions in the terminal

process.versions

Conclusion

Learned multiple ways to get node npm version using javascript code and interactive REPL terminal.

THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
Subscribe
You'll get a notification every time a post gets published here.