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!

 

 

TABLE OF CONTENTS

 

DOWNLOAD & NOTES

Here is the download link to the example code, so you don’t have to copy-paste everything.

 

EXAMPLE CODE DOWNLOAD

Source code on GitHub Gist

Just click on “download zip” or do a git clone. I have released it under the MIT license, so feel free to build on top of it or use it in your own project.

 

SORRY FOR THE ADS...

But someone has to pay the bills, and sponsors are paying for it. I insist on not turning Code Boxx into a "paid scripts" business, and I don't "block people with Adblock". Every little bit of support helps.

Buy Me A Coffee Code Boxx eBooks

 

 

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
v19.0.0

C:\>node
Welcome to Node.js v19.0.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
v19.0.0
{
  node: '19.0.0',
  v8: '10.7.193.13-node.16',
  uv: '1.43.0',
  zlib: '1.2.11',
  brotli: '1.0.9',
  ares: '1.18.1',
  modules: '111',
  nghttp2: '1.47.0',
  napi: '8',
  llhttp: '8.1.0',
  openssl: '3.0.5+quic',
  cldr: '41.0',
  icu: '71.1',
  tz: '2022b',
  unicode: '14.0',
  ngtcp2: '0.8.1',
  nghttp3: '0.7.0'
}
  • 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[0]); // MAJOR
console.log(version[1]); // MINOR
console.log(version[2]); // PATCH

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

 

EXTRAS

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

 

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 *