How to Check Current Node Version at Runtime
Table of Contents
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.
JAVASCRIPTconst version = process.version;
console.log(version);
BASHv18.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:
JAVASCRIPTconst 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.
JAVASCRIPTconst version = process.versions.node;
console.log(version);
BASHv18.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!
- How to Install Node on Windows, macOS and Linux
- Create an RSS Reader in Node
- How to Set Up Cron Jobs in Linux
- Best Visual Studio Code Extensions for 2022
- How to deploy a PHP app using Docker
- How to Scrape the Web using Node.js and Puppeteer
- Getting Started with Moment.js
- Getting Started with React
- Setting Up Stylus CSS Preprocessor
- Getting Started with Vuex: Managing State in Vue
- Using Axios to Pull Data from a REST API
- How To Create a Modal Popup Box with CSS and JavaScript