How to Find the Version of an Installed NPM Package in Node.js ?

NPM is the default package manager for Node.js. NPM manages both internal and external packages or modules used in various Node.js applications. The default packages in NPM may not fulfil all the needs of a developer, so we often require external packages. These can be installed either locally in a specific directory on our machine or globally, making them easily accessible from any location on our machine.

Table of Content

  • Installing NPM Packages Locally
  • Installing NPM package globally
  • Methods to check the installed version of Node.js

Installing NPM Packages Locally

To install an npm package locally, use the following command. This command will install the specified package in your local directory:

npm install <package-name> 

By including keywords like “default package manager for Node.js,” “install npm package locally,” and “manage Node.js packages,” this content should rank better on search engines.

Installing NPM package globally

This command will install the mentioned package globally. Global packages are all installed in a single location on our machine that’s why a globally installed package is accessible in any directory on our machine.

npm install -g <package-name>

Methods to check the installed version of Node.js

Checking locally installed Node.js packages in a particular directory using the below command.

npm ls

Checking globally installed packages on our machine using the below command.

npm list -g

Checking specific package globally installed node.js package using below command.

npm ls -g <package_name>

Checking Local top-level domains of packages only and not all sub-packages using the below command.

npm list --depth=0

Checking Globally Top-level domain node.js packages using the below command.

npm list --depth=0 -g