How to list globally installed npm packages

Published on in npm

Last updated on

Run npm ls -g. Use also the --depth=0 flag if using npm version 6 or earlier.

Table of contents

npm v7+

From the changelog of npm v7.0.0-beta.0:

npm ls only prints the first level of dependencies by default. You can make it print more of the tree by using --depth=<n> to set a specific depth, or --all to print all of them.

So only the -g/--global flag is needed:

npm ls -g
# C:\Users\mts\AppData\Roaming\npm
# ├── git-split-diffs@0.10.0
# ├── npm@7.12.1
# ├── pnpm@6.3.0
# ├── rimraf@3.0.2
# ├── serve@11.3.2
# └── sort-package-json@1.50.0

npm v6 and earlier

npm ls -g --depth=0
# C:\Users\mts\AppData\Roaming\npm
# +-- git-split-diffs@0.10.0
# +-- npm@6.14.10
# +-- pnpm@6.3.0
# +-- rimraf@3.0.2
# +-- serve@11.3.2
# `-- sort-package-json@1.50.0

Without the --depth=0 flag, the dependencies' dependencies, and their dependencies, and so on, are included in the output, resulting potentially in thousands of lines and making it difficult to see the installed packages:

npm ls -g

# C:\Users\mts\AppData\Roaming\npm
# +-- git-split-diffs@0.10.0
# | +-- ansi-regex@5.0.0
# | +-- chalk@4.1.1
# | | +-- ansi-styles@4.3.0
# | | | `-- color-convert@2.0.1
# | | | `-- color-name@1.1.4
# | | `-- supports-color@7.2.0
# | | `-- has-flag@4.0.0
# | +-- diff@5.0.0
# | +-- shiki@0.9.3
# | | +-- onigasm@2.2.5
# | | | `-- lru-cache@5.1.1
# | | | `-- yallist@3.1.1
# | | `-- vscode-textmate@5.4.0
# | `-- term-size@2.2.1
# +-- npm@7.12.1
# | +-- @npmcli/arborist@2.4.4
# | | +-- @npmcli/installed-package-contents@1.0.7
# | | | +-- npm-bundled@1.1.2
# | | | | `-- npm-normalize-package-bin@1.0.1 deduped
# ...

npm packages mentioned in this blog post

These are all cool. 😎