How To Check NodeJS Version (Command Line & Runtime)

Welcome to a quick tutorial on how to check the NodeJS version. Need to check the current version of your Node installation? Or check if users meet the basic version requirement?

  1. To check the NodeJS version in the command line, run node -v.
  2. To get the NodeJS version during runtime – console.log(process.version);

That covers the basics, but read on for more details!

ⓘ I have included a zip file with all the source code at the start of this tutorial, so you don’t have to copy-paste everything… Or if you just want to dive straight in.

 

 

TABLE OF CONTENTS

Download & Notes NodeJS Version Useful Bits & Links
The End

 

DOWNLOAD & NOTES

Firstly, here is the download link to the example code as promised.

 

QUICK NOTES

If you spot a bug, feel free to comment below. I try to answer short questions too, but it is one person versus the entire world… If you need answers urgently, please check out my list of websites to get help with programming.

 

EXAMPLE CODE DOWNLOAD

Click here to download all the example source code, I have released it under the MIT license, so feel free to build on top of it or use it in your own project.

 

 

NODEJS VERSION CHECK

All right, let us now get into the ways to check the version in NodeJS. Also, trivial information on the version number.

 

1) COMMAND LINE VERSION CHECK

C:\>node -v
v17.4.0

C:\>node
Welcome to Node.js v17.4.0.
Type ".help" for more information.
>

As in the introduction, simply run node -v or node --version in the command line to get the Node version. But of course, the version number is also right in the first line when we launch it.

 

2) RUNTIME VERSION CHECK

2-runtime.js
// (A) VERSION NUMBER ONLY
console.log(process.version);
 
// (B) INCLUDE DEPENDENCIES
console.log(process.versions);
C:\>node 2-runtime.js
{
  node: '17.4.0',
  v8: '9.6.180.15-node.13',
  uv: '1.43.0',
  zlib: '1.2.11',
  brotli: '1.0.9',
  ares: '1.18.1',
  modules: '102',
  nghttp2: '1.45.1',
  napi: '8',
  llhttp: '6.0.4',
  openssl: '3.0.1+quic',
  cldr: '40.0',
  icu: '70.1',
  tz: '2021a3',
  unicode: '14.0',
  ngtcp2: '0.1.0-DEV',
  nghttp3: '0.1.0-DEV'
}
  • process.version Is a string that holds the version number.
  • process.versions Is an object that holds the version number of Node, as well as all of its dependencies.

 

 

3) VERSION NUMBER BREAK DOWN

3-version.js
var version = process.version.split(".");
version.forEach((v, i) => {
  version[i] = parseInt(v.replace("v",""));
});
console.log(version);

For you guys who want to break the major-minor-patch versions into an array, here’s a simple snippet.

 

USEFUL BITS & LINKS

That’s all for the tutorial, and here is a small section on some extras and links that may be useful to you.

 

EXTRA) SEMANTIC VERSION

For you beginners who do not know, that v12.3.4 “sequence” of version number is called “semantic versioning” in the cyber world.

  • The first v12 is the major version.
  • .3 is the minor version.
  • Lastly, .4 is the patch version.

Why the trouble? The general guidelines are:

  • Major version should change when the upgrades are not backward-compatible.
  • Minor version should change when backward-compatible additions are done.
  • Patch version is self-explanatory… No changes in the functionality, only bug fixes.

 

 

LINKS & REFERENCES

 

INFOGRAPHIC CHEAT SHEET

How To Check NodeJS Version (Click To Enlarge)

 

THE END

Thank you for reading, and we have come to the end. I hope that it has helped you to better understand, and if you want to share anything with this guide, please feel free to comment below. Good luck and happy coding!

Leave a Comment

Your email address will not be published. Required fields are marked *