Detect the Node.js Version in a Running Process or App

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

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.

Mentioned Resources

Explore the Library

Find interesting tutorials and solutions for your problems.