How to Check Current Node Version at Runtime

Updated onbyAlan Morel
How to Check Current Node Version at Runtime

Node, like any popular library/framework, gets regular updates over time.

These updates lead to new version numbers, allowing you to decide what version you would like your code to target.

It can helpful to know what version your code is running on as it lets you know what features you have access to.

In this post, we'll look at how to check the current version of your Node instance at runtime.

Check the current version of Node

The best way to check the current version of Node is to use the process.version property.

This property comes directly from Node and contains the version of Node that is running.

JAVASCRIPT
const version = process.version; console.log(version);
BASH
v18.0.0

This property will be a string that starts with v and ends with the version number.

Alternatively, you can use the process.versions property.

This property will return all the versions of the different software that Node uses.

Here's an example:

JAVASCRIPT
const versions = process.versions; console.log(versions);
JAVASCRIPT
{ node: '18.0.0', v8: '10.1.124.8-node.13', uv: '1.43.0', zlib: '1.2.11', brotli: '1.0.9', ares: '1.18.1', modules: '108', nghttp2: '1.47.0', napi: '8', llhttp: '6.0.4', openssl: '3.0.2+quic', cldr: '41.0', icu: '71.1', tz: '2022a', unicode: '14.0', ngtcp2: '0.1.0-DEV', nghttp3: '0.1.0-DEV' }

From here, you can extract the version of Node that is running.

JAVASCRIPT
const version = process.versions.node; console.log(version);
BASH
v18.0.0

Conclusion

In this post, we've looked at how to check the current version of Node at runtime.

Using that, you can be made aware of what features you have access to while your code is running.

Thanks for reading!

To learn more about web development, founding a start-up, and bootstrapping a SaaS, follow me on X!
Copyright © 2017 - 2024 Sabe.io. All rights reserved. Made with ❤ in NY.