SoFunction
Updated on 2025-03-10

Six ways to quickly query nodejs version information

1. Use the node command to query version information

The node command provides a parameter -v that can output version information in the console. Enter the following command in the terminal to query the version:

$ node -v

The query results are similar to:
v14.16.0

2. Use process objects to query version information

The process object is a built-in object that can be used to get the currently running version. Add the following code to the JavaScript file to query version information:

();

The output result is:
v14.16.0

3. Use npm to query version information

npm is a package manager that can query version information through the npm command. Enter the following command in the terminal to query version information:

$ npm version node

The running result is:
v14.16.0

4. Use nvm to query version information

nvm (Node Version Manager) is a version management tool that can easily manage multiple versions. Enter the following command in the terminal to query the currently used version:

$ nvm current

The output result is:
v14.16.0

Use the following command to list all versions that have been installed on the current system:

$ nvm ls

The running result is:
->       v14.16.0
         v10.19.0
         v12.18.3
default -> node (-> v14.16.0)

5. Use query version information

In the root directory of the application, there is a file named that records the application's dependencies and version information. In this file, we can view the version information on which the current application depends.

Open the file and you can see the following content:

{
  "name": "nodejs-demo",
  "version": "1.0.0",
  "dependencies": {
    "express": "^4.17.1"
  },
  "devDependencies": {},
  "scripts": {
    "start": "node "
  },
  "engines": {
    "node": ">=14.0.0"
  }
}

In the engines field, you can see the version range that the current application depends on.

6. Use the HTTP API to query version information

Provides some basic HTTP modules, which can implement HTTP APIs that obtain version information by writing JavaScript scripts. The following is the code to query version information using the HTTP API:

const http = require('http');
 
const server = ((request, response) => {
  (200, { 'Content-Type': 'text/plain' });
  ();
});
 
const PORT = 8080;
(PORT, () => {
  (`Server running at http://localhost:${PORT}/`);
});

This code creates an HTTP server. When a URL with port 8080 is requested to access, the current version information will be returned.

This is the end of this article about six ways to quickly query nodejs version information. For more information about query nodejs version information, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!