Terminus by Warp
List Installed Npm Packages

List Installed Npm Packages

Razvan Ludosanu
Razvan Ludosanu
Founder, learnbackend.dev

The short answer

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

 $ npm ls -g

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

 $ cd /path/to/project
$ npm ls

[#easily-recall-with-ai]Easily retrieve this command using Warp’s AI Command Search[#easily-recall-with-ai]

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

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

[#more-about-npm-g]Globally installed packages and -g[#more-about-npm-g]

The [.inline-code]-g[.inline-code] flag is used with [.inline-code]npm[.inline-code] to manage globally installed packages on your machine. It can be used with commands such as [.inline-code]npm install[.inline-code], [.inline-code]npm uninstall[.inline-code], [.inline-code]npm ls[.inline-code], 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-local-dependency-tree]Show the dependency tree of installed packages[#show-local-dependency-tree]

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

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

To recursively list the dependencies of top-level packages, you can use the [.inline-code]--depth[.inline-code] flag as follows:

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

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

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

 $ npm ls --depth 1

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

 $ npm ls --depth 2

Note that, running [.inline-code]npm ls[.inline-code] is equivalent to [.inline-code]npm ls --depth=0[.inline-code], and running [.inline-code]npm ls --depth[.inline-code] is equivalent to [.inline-code]npm ls --depth=1[.inline-code]

[#show-all-local-dependencies]Show all dependencies[#show-all-local-dependencies]

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

 $ npm ls --all [-g]

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:

[#package-lock-json]Show the dependency tree using the package-lock.json file[#package-lock-json]

By default, the [.inline-code]npm ls[.inline-code] command will show the dependency tree of installed packages only.

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

 $ npm ls --package-lock-only

[#package-json]View a project's dependencies using the package.json file[#package-json]

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

 $ cat package.json

Experience the power of Warp

  • Write with an IDE-style editor
  • Easily navigate through output
  • Save commands to reuse later
  • Ask Warp AI to explain or debug
  • Customize keybindings and launch configs
  • Pick from preloaded themes or design your own
brew install --cask warp
Copied!
Join the Windows waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.
Join the Linux waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.
Join the Linux waitlist or join the Windows waitlist
Join the Windows waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.