Node.js — Determine the Node.js Version Running Your Script

When running a Node.js script you may need to ensure a given Node.js version that runs your script. This happens when you need a given feature that became available in a specific Node.js release.

For example, you may require at least Node.js version 14.17.5 (or later) or you’re not able to run the given script. You may then stop processing and show a message to the user asking to update the Node.js installation.

This tutorial shows you how to check the Node.js version that is currently running your script file.

Node.js Series Overview

  1. Determine the Node.js Version Running Your Script

Check the Node.js Version Running Your Script

Every application running with Node.js has access to the global process object. The process provides information about the Node.js process running the script.

You can retrieve the Node.js version in two ways:
- process.version: returns the Node.js version as a string starting with the v prefix - process.versions.node: returns the Node.js as a string

Here’s a code snippet showing the returned versions of each property:

process.version  
// v14.17.5

process.versions.node  
// 14.17.5

That’s it!


Mentioned Resources

Explore the Library

Find interesting tutorials and solutions for your problems.