ou may want to retrieve the Node.js version running the current process during runtime. For example, you may enforce a certain Node.js release line or at least a specified version while providing a package to the public.
Node.js comes with a handy way to detect which Node.js version is running the process. And this tutorial shows you how to retrieve it.
Node.js Series Overview
- Increase the Memory Limit for Your Process
- Why You Should Add “node” in Your Travis Config
- Create a PDF from HTML with Puppeteer and Handlebars
- Create Your Own Custom Error
- Extend Multiple Classes (Multi Inheritance)
- Get a File’s Created Date
- Get a File’s Last Modified/Updated Date
- Write a JSON Object to a File
- How to Create an Empty File
- Generate a Random Number in Range With JavaScript/Node.js
- How to Merge Objects
- Retrieve a Request’s IP Address in Node.js
- Detect the Node.js Version in a Running Process or App
- Install Dependencies for a Specific Package
- String Replace All Appearances
- Remove All Whitespace From a String in JavaScript
- Generate a Random String in Node.js or JavaScript
- Remove Extra Spaces From a String in JavaScript or Node.js
- Remove Numbers From a String in JavaScript or Node.js
- Get the Part Before a Character in a String in JavaScript or Node.js
- Get the Part After a Character in a String in JavaScript or Node.js
- How to Check if a Value is a String in JavaScript or Node.js
- Check If a String Includes All Strings in JavaScript/Node.js/TypeScript
- How to Run an Asynchronous Function in Array.map()
- How to Reset and Empty an Array
- for…of vs. for…in Loops
- Clone/Copy an Array in JavaScript and Node.js
- Get an Array With Unique Values (Delete Duplicates)
- Sort an Array of Integers in JavaScript and Node.js
- Sort a Boolean Array in JavaScript, TypeScript, or Node.js
- Check If an Array Contains a Given Value in JavaScript or Node.js
- Add an Item to the Beginning of an Array in JavaScript or Node.js (Coming soon)
- Append an Item at the End of an Array in JavaScript or Node.js (Coming soon)
- Callback and Promise Support in your Node.js Modules
- Run Async Functions/Promises in Sequence
- Run Async Functions/Promises in Parallel
- Run Async Functions in Batches
- How to Fix “Promise resolver undefined is not a function” in Node.js or JavaScript
- Detect if Value Is a Promise in Node.js and JavaScript
- How to Check if an Object is Empty in JavaScript or Node.js
- How to CamelCase Keys of an Object in JavaScript or Node.js (Coming soon)
Detect the Node.js Version at Runtime
Node.js handles apps and services as a long-running process. The Node.js runtime comes with a process
package. The process
package is globally available in your Node.js app, meaning you can access it in every JavaScript or TypeScript file via the process
identifier.
The process comes with two ways retrieving the executing Node.js version at runtime.
The first way is process.version
returning the version string including the v
prefix.
The second way is via process.versions.node
returning an object listing the version of Node.js and all its dependencies. Accessing this property returns the plain version string in semver format (major.minor.patch
):
const version = process.version
// v12.10.1
// Or
const version = process.versions.node
// 12.10.1
When displaying the Node.js version in an overview, you may use the version with “v” prefix. If you want to parse and reuse the version, it may come handy to use the plain version string without the “v” prefix.