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 Serve Static Files with Nginx and Docker
How to deploy a .NET app using Docker
Best Visual Studio Code Extensions for 2022
How to build a Discord bot using TypeScript
How to deploy a PHP app using Docker
Using Puppeteer and Jest for End-to-End Testing
How to Scrape the Web using Node.js and Puppeteer
Getting Started with Moment.js
Using Push.js to Display Web Browser Notifications
Building a Real-Time Note-Taking App with Vue and Firebase
Getting Started with React
Getting Started with Moon.js
