• Modern UX

    Edit and navigate faster in the terminal with Warp's IDE-like input editor.

  • Warp AI

    AI suggests what commands to run and learns from your documentation.

  • Agent Mode

    Delegate tasks to AI and use natural language on the command line.

  • Warp Drive

    Save and share interactive notebooks, workflows, and environment variables.

  • All Features

Check Npm Package Version

Thumbnail for Glory KimGlory Kim

Glory Kim

Software Engineer, Loom

Published: 2/1/2024

About Terminus

The short answer

To check the currently installed version (i.e. the “node modules version”) of a specific package in your project, you can use the npm ls command (alias for npm list) as follows:

 $ npm ls <package-name>

Run in Warp

For example, if running npm ls msw outputs [email protected], it means that the version 0.42.1 of the msw package has been installed within the node_modules directory of your project.

 $ npm ls msw
[email protected] /epic-react/testing-react-apps
└── [email protected]

Run in Warp

You can get the list of available npm versions on the official npmjs website.

npm check if the package is installed at all

On the other hand, if running npm ls testcafe outputs (empty), it means that this package has not been installed within your project.

 $ npm ls testcafe
[email protected] /epic-react/testing-react-apps
└── (empty)

Run in Warp

We have another post on npm list installed packages which explores how to view all of the installed packages both locally and globally. 

If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Search feature:

Thumbnail for

This feature is a game-changer and it allows developers to maintain flow and easily look up commands without leaving their terminal.

Typing # and entering check package version in the AI Command Search will prompt a npm list command that can then quickly be inserted into your shell by doing CMD+ENTER.

The difference between the package.json file and the node_modules folder

Many developers tend to rely on the package.json file to determine the version of an  installed package. We would recommend using the commands listed above instead. The package.json file is used to map the package to a version range and note the project’s requirements. The node_modules folder contains the installed version of the package and represents the exact version of the code that has been downloaded.

 // package.json file
{
  "name": "project-name",
  "version": "0.0.",
  "dependencies": {
    ….
    "lodash": "^4.17.21"
  }
}

Run in Warp

In the above example, the lodash version contains a caret (^) operator. This indicates that the project is compatible with any lodash version greater than 4.17.21 but less than 5.0.0. Thus, the version installed within the node_modules directory can be 4.17.25 and it'll still fall within the package.json specifications.

 $ which npm

Run in Warp

View package information

To view information about a package available on the npm registry, you can use the following command:

 $ npm view <package-name>

Run in Warp

Which will, by default, output information about its latest version.

To view information about a package at a specific version, you can append the version number to the package name as follows:

 npm view [email protected]

Run in Warp

Thumbnail for

Available versions of a package

In order to view all of the available versions of a specific package, you can append the versions argument to the npm view command as follows:

 $ npm view <package-name> versions

Run in Warp

Using npm-check

If your project contains many dependencies and you prioritize actively maintaining them, you might want to consider using the npm-check package to manage them.

The npm-check library provides a user-friendly command line interface to check for incorrect dependencies, remove unused packages, update modules, and view package details. It also has an interactive interface which prevents user errors like typos.

However, if your project is relatively small, then the npm CLI commands should be more than enough for your use case. For example, if you wanted to update your packages, you can leverage the existing npm update command. And as mentioned above, the npm view command can give you more details about a package.

Written by

Thumbnail for Glory KimGlory Kim

Glory Kim

Software Engineer, Loom

Filed Under

Related Articles

Removing npm Packages

Learn how to remove packages locally, globally, and from the registry using the npm uninstall command.

Npm
Thumbnail for Utsav PoudelUtsav Poudel

Execute Packages With npx And npm

Discover the power of npm's npx tool, a developer's best friend for running packages without global installs.

Npm
Thumbnail for Glory KimGlory Kim

Install Dev Dependencies With npm

Learn how to install and update dev dependencies using the npm install command.

Npm
Thumbnail for Mansi ManhasMansi Manhas

Clear npm Cache

Learn how to clear the npm cache on Linux, macOS, and Windows.

NpmLinux
Thumbnail for Razvan LudosanuRazvan Ludosanu

How To Update NPM

Learn how to update npm to a specific version using the npm, nvm, or npx commands.

Npm
Thumbnail for Razvan LudosanuRazvan Ludosanu

Re-Installing Npm

Learn how to reinstall Node.js and npm on macOS, Linux, and Windows using `curl`, `brew`, `apt`, `nvm`, and Node installer.

Npm
Thumbnail for Razvan LudosanuRazvan Ludosanu

How To Reinstall Packages With Npm

Brief guide to reinstalling npm packages using npm

Npm
Thumbnail for Glory KimGlory Kim

Install NPM Packages From GitHub

Check an npm package version within your project

Npm
Thumbnail for Razvan LudosanuRazvan Ludosanu

List Installed Npm Packages

Learn how to list globally and locally installed packages with npm, including their dependencies.

Npm
Thumbnail for Razvan LudosanuRazvan Ludosanu

Trusted by hundreds of thousands of professional developers

Download Warp to get started

Download for Mac
Thumbnail for null