• 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

List Installed Npm Packages

Thumbnail for Razvan LudosanuRazvan Ludosanu

Razvan Ludosanu

Founder, learnbackend.dev

Published: 2/1/2024

About Terminus

The short answer

To list globally installed packages with npm, you can use the npm ls command combined with the -g flag (short for global):

 $ npm ls -g

Run in Warp

Alternatively, to list locally installed packages present in the node_modules folder of a project, you can navigate to your project and run the npm ls command (without the -g flag):

 $ cd /path/to/project
$ npm ls

Run in Warp

Easily retrieve this command using Warp’s AI Command Search

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

Thumbnail for

Entering list globally installed packages npm in the AI Command Search will prompt a npm command that can then quickly be inserted into your shell by doing CMD+ENTER.

Globally installed packages and -g

The -g flag is used with npm to manage globally installed packages on your machine. It can be used with commands such as npm install, npm uninstall, npm ls, and so on.

Globally installed packages are located in npm's default directory, and may include modules accessible by any project or application on your machine, or command-line tools that can be run from any directory.

While convenient, it's important to note that global packages can lead to version conflicts if different projects rely on different versions of the same package. It is therefore generally recommended to install project-specific dependencies to maintain isolation and avoid conflicts.

Show the dependency tree of installed packages

Packages installed with npm often rely on other packages referred to as dependencies, which can also rely on other dependencies, and so on.

By default, the npm ls command will only show the top-level packages of the root project or the global directory (if combined with the -g flag).

To recursively list the dependencies of top-level packages, you can use the --depth flag as follows:

 $ curl -L --max-redirs 5 <url>

Run in Warp

Where N is a number representing the depth of the shown dependency tree.

For example, this command will only show top-level packages, without their dependencies:

 $ npm ls --depth 0

Run in Warp

This command will show top-level packages and their immediate dependencies:

 $ npm ls --depth 1

Run in Warp

And this command will show top-level packages, their dependencies, and the immediate dependencies of those dependencies:

 $ npm ls --depth 2

Run in Warp

Note that, running npm ls is equivalent to npm ls --depth=0, and running npm ls --depth is equivalent to npm ls --depth=1

Show all dependencies

To show the entire dependency tree of locally and globally installed packages, you can use the --all flag as follows:

 $ npm ls --all [-g]

Run in Warp

Where N is a number representing the depth of the shown dependency tree.

For example, this command will only show top-level packages, without their dependencies:

Show the dependency tree using the package-lock.json file

By default, the npm ls command will show the dependency tree of installed packages only.

To show the dependency tree of a project that doesn't contain a node_modules folder based on its package-lock.json file, you can use the --package-lock-only flag as follows:

 $ npm ls --package-lock-only

Run in Warp

View a project's dependencies using the package.json file

Another way to view a project's dependency list without using the npm ls command is to display the package.json file using commands such as cat or less, and look for the dependencies, devDependencies, peerDependencies, and optionalDependencies properties within this file.

 $ cat package.json

Run in Warp

Written by

Thumbnail for Razvan LudosanuRazvan Ludosanu

Razvan Ludosanu

Founder, learnbackend.dev

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

Check Npm Package Version

Check an npm package version within your project

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

Trusted by hundreds of thousands of professional developers

Download Warp to get started

Download for Mac
Request demo
Thumbnail for null