patch-1
@reggi/path-to-regexp
dependabot/npm_and_yarn/main/copy-to-clipboard-4.0.2
dependabot/npm_and_yarn/main/eslint-10.4.0
dependabot/npm_and_yarn/main/npmcli/eslint-config-7.0.0
dependabot/npm_and_yarn/main/proc-log-7.0.0
dependabot/npm_and_yarn/npm_and_yarn-826852524d
dependabot/npm_and_yarn/npm_and_yarn-ab9a7f4bc2
deprecate-totp-2fa
dhei/classic-tokens
gat-bypass-2fa-docs
jpg619/fix-accessibility-content-flow
jpg619/version-bump-tar-2
kartykp/gat-bypass-2fa-docs
kartykp/upgrade-path-to-regex
main
maitxn/version-bump-tar
patch-1
reggi/cache-based-on-version
reggi/dev-engines
reggi/fix-transform-prettier
reggi/overrides
update-search-sensitivity
| 1 | --- |
| 2 | title: npm-ls |
| 3 | section: 1 |
| 4 | description: List installed packages |
| 5 | github_repo: npm/cli |
| 6 | github_branch: release/v9 |
| 7 | github_path: docs/lib/content/commands/npm-ls.md |
| 8 | redirect_from: |
| 9 | - /cli-documentation/v9/cli-commands/ls |
| 10 | - /cli-documentation/v9/cli-commands/npm-ls |
| 11 | - /cli-documentation/v9/commands/ls |
| 12 | - /cli-documentation/v9/commands/npm-ls |
| 13 | - /cli-documentation/v9/ls |
| 14 | - /cli-documentation/v9/npm-ls |
| 15 | - /cli/v9/cli-commands/ls |
| 16 | - /cli/v9/cli-commands/npm-ls |
| 17 | - /cli/v9/commands/ls |
| 18 | - /cli/v9/ls |
| 19 | - /cli/v9/npm-ls |
| 20 | --- |
| 21 | |
| 22 | ### Synopsis |
| 23 | |
| 24 | ```bash |
| 25 | npm ls <package-spec> |
| 26 | |
| 27 | alias: list |
| 28 | ``` |
| 29 | |
| 30 | ### Description |
| 31 | |
| 32 | This command will print to stdout all the versions of packages that are installed, as well as their dependencies when `--all` is specified, in a tree structure. |
| 33 | |
| 34 | Note: to get a "bottoms up" view of why a given package is included in the tree at all, use [`npm explain`](/cli/v9/commands/npm-explain). |
| 35 | |
| 36 | Positional arguments are `name@version-range` identifiers, which will limit the results to only the paths to the packages named. Note that nested packages will _also_ show the paths to the specified packages. For example, running `npm ls promzard` in npm's source tree will show: |
| 37 | |
| 38 | ```bash |
| 39 | npm@9.9.4 /path/to/npm |
| 40 | └─┬ init-package-json@0.0.4 |
| 41 | └── promzard@0.1.5 |
| 42 | ``` |
| 43 | |
| 44 | It will print out extraneous, missing, and invalid packages. |
| 45 | |
| 46 | If a project specifies git urls for dependencies these are shown in parentheses after the `name@version` to make it easier for users to recognize potential forks of a project. |
| 47 | |
| 48 | The tree shown is the logical dependency tree, based on package dependencies, not the physical layout of your `node_modules` folder. |
| 49 | |
| 50 | When run as `ll` or `la`, it shows extended information by default. |
| 51 | |
| 52 | ### Note: Design Changes Pending |
| 53 | |
| 54 | The `npm ls` command's output and behavior made a _ton_ of sense when npm created a `node_modules` folder that naively nested every dependency. In such a case, the logical dependency graph and physical tree of packages on disk would be roughly identical. |
| 55 | |
| 56 | With the advent of automatic install-time deduplication of dependencies in npm v3, the `ls` output was modified to display the logical dependency graph as a tree structure, since this was more useful to most users. However, without using `npm ls -l`, it became impossible to show _where_ a package was actually installed much of the time! |
| 57 | |
| 58 | With the advent of automatic installation of `peerDependencies` in npm v7, this gets even more curious, as `peerDependencies` are logically "underneath" their dependents in the dependency graph, but are always physically at or above their location on disk. |
| 59 | |
| 60 | Also, in the years since npm got an `ls` command (in version 0.0.2!), dependency graphs have gotten much larger as a general rule. Therefore, in order to avoid dumping an excessive amount of content to the terminal, `npm ls` now only shows the _top_ level dependencies, unless `--all` is provided. |
| 61 | |
| 62 | A thorough re-examination of the use cases, intention, behavior, and output of this command, is currently underway. Expect significant changes to at least the default human-readable `npm ls` output in npm v8. |
| 63 | |
| 64 | ### Configuration |
| 65 | |
| 66 | #### `all` |
| 67 | |
| 68 | - Default: false |
| 69 | - Type: Boolean |
| 70 | |
| 71 | When running `npm outdated` and `npm ls`, setting `--all` will show all outdated or installed packages, rather than only those directly depended upon by the current project. |
| 72 | |
| 73 | #### `json` |
| 74 | |
| 75 | - Default: false |
| 76 | - Type: Boolean |
| 77 | |
| 78 | Whether or not to output JSON data, rather than the normal output. |
| 79 | |
| 80 | - In `npm pkg set` it enables parsing set values with JSON.parse() before saving them to your `package.json`. |
| 81 | |
| 82 | Not supported by all npm commands. |
| 83 | |
| 84 | #### `long` |
| 85 | |
| 86 | - Default: false |
| 87 | - Type: Boolean |
| 88 | |
| 89 | Show extended information in `ls`, `search`, and `help-search`. |
| 90 | |
| 91 | #### `parseable` |
| 92 | |
| 93 | - Default: false |
| 94 | - Type: Boolean |
| 95 | |
| 96 | Output parseable results from commands that write to standard output. For `npm search`, this will be tab-separated table format. |
| 97 | |
| 98 | #### `global` |
| 99 | |
| 100 | - Default: false |
| 101 | - Type: Boolean |
| 102 | |
| 103 | Operates in "global" mode, so that packages are installed into the `prefix` folder instead of the current working directory. See [folders](/cli/v9/configuring-npm/folders) for more on the differences in behavior. |
| 104 | |
| 105 | - packages are installed into the `{prefix}/lib/node_modules` folder, instead of the current working directory. |
| 106 | - bin files are linked to `{prefix}/bin` |
| 107 | - man pages are linked to `{prefix}/share/man` |
| 108 | |
| 109 | #### `depth` |
| 110 | |
| 111 | - Default: `Infinity` if `--all` is set, otherwise `1` |
| 112 | - Type: null or Number |
| 113 | |
| 114 | The depth to go when recursing packages for `npm ls`. |
| 115 | |
| 116 | If not set, `npm ls` will show only the immediate dependencies of the root project. If `--all` is set, then npm will show all dependencies by default. |
| 117 | |
| 118 | #### `omit` |
| 119 | |
| 120 | - Default: 'dev' if the `NODE_ENV` environment variable is set to 'production', otherwise empty. |
| 121 | - Type: "dev", "optional", or "peer" (can be set multiple times) |
| 122 | |
| 123 | Dependency types to omit from the installation tree on disk. |
| 124 | |
| 125 | Note that these dependencies _are_ still resolved and added to the `package-lock.json` or `npm-shrinkwrap.json` file. They are just not physically installed on disk. |
| 126 | |
| 127 | If a package type appears in both the `--include` and `--omit` lists, then it will be included. |
| 128 | |
| 129 | If the resulting omit list includes `'dev'`, then the `NODE_ENV` environment variable will be set to `'production'` for all lifecycle scripts. |
| 130 | |
| 131 | #### `link` |
| 132 | |
| 133 | - Default: false |
| 134 | - Type: Boolean |
| 135 | |
| 136 | Used with `npm ls`, limiting output to only those packages that are linked. |
| 137 | |
| 138 | #### `package-lock-only` |
| 139 | |
| 140 | - Default: false |
| 141 | - Type: Boolean |
| 142 | |
| 143 | If set to true, the current operation will only use the `package-lock.json`, ignoring `node_modules`. |
| 144 | |
| 145 | For `update` this means only the `package-lock.json` will be updated, instead of checking `node_modules` and downloading dependencies. |
| 146 | |
| 147 | For `list` this means the output will be based on the tree described by the `package-lock.json`, rather than the contents of `node_modules`. |
| 148 | |
| 149 | #### `unicode` |
| 150 | |
| 151 | - Default: false on windows, true on mac/unix systems with a unicode locale, as defined by the `LC_ALL`, `LC_CTYPE`, or `LANG` environment variables. |
| 152 | - Type: Boolean |
| 153 | |
| 154 | When set to true, npm uses unicode characters in the tree output. When false, it uses ascii characters instead of unicode glyphs. |
| 155 | |
| 156 | #### `workspace` |
| 157 | |
| 158 | - Default: |
| 159 | - Type: String (can be set multiple times) |
| 160 | |
| 161 | Enable running a command in the context of the configured workspaces of the current project while filtering by running only the workspaces defined by this configuration option. |
| 162 | |
| 163 | Valid values for the `workspace` config are either: |
| 164 | |
| 165 | - Workspace names |
| 166 | - Path to a workspace directory |
| 167 | - Path to a parent workspace directory (will result in selecting all workspaces within that folder) |
| 168 | |
| 169 | When set for the `npm init` command, this may be set to the folder of a workspace which does not yet exist, to create the folder and set it up as a brand new workspace within the project. |
| 170 | |
| 171 | This value is not exported to the environment for child processes. |
| 172 | |
| 173 | #### `workspaces` |
| 174 | |
| 175 | - Default: null |
| 176 | - Type: null or Boolean |
| 177 | |
| 178 | Set to true to run the command in the context of **all** configured workspaces. |
| 179 | |
| 180 | Explicitly setting this to false will cause commands like `install` to ignore workspaces altogether. When not set explicitly: |
| 181 | |
| 182 | - Commands that operate on the `node_modules` tree (install, update, etc.) will link workspaces into the `node_modules` folder. - Commands that do other things (test, exec, publish, etc.) will operate on the root project, _unless_ one or more workspaces are specified in the `workspace` config. |
| 183 | |
| 184 | This value is not exported to the environment for child processes. |
| 185 | |
| 186 | #### `include-workspace-root` |
| 187 | |
| 188 | - Default: false |
| 189 | - Type: Boolean |
| 190 | |
| 191 | Include the workspace root when workspaces are enabled for a command. |
| 192 | |
| 193 | When false, specifying individual workspaces via the `workspace` config, or all workspaces via the `workspaces` flag, will cause npm to operate only on the specified workspaces, and not on the root project. |
| 194 | |
| 195 | This value is not exported to the environment for child processes. |
| 196 | |
| 197 | #### `install-links` |
| 198 | |
| 199 | - Default: false |
| 200 | - Type: Boolean |
| 201 | |
| 202 | When set file: protocol dependencies will be packed and installed as regular dependencies instead of creating a symlink. This option has no effect on workspaces. |
| 203 | |
| 204 | ### See Also |
| 205 | |
| 206 | - [package spec](/cli/v9/using-npm/package-spec) |
| 207 | - [npm explain](/cli/v9/commands/npm-explain) |
| 208 | - [npm config](/cli/v9/commands/npm-config) |
| 209 | - [npmrc](/cli/v9/configuring-npm/npmrc) |
| 210 | - [npm folders](/cli/v9/configuring-npm/folders) |
| 211 | - [npm explain](/cli/v9/commands/npm-explain) |
| 212 | - [npm install](/cli/v9/commands/npm-install) |
| 213 | - [npm link](/cli/v9/commands/npm-link) |
| 214 | - [npm prune](/cli/v9/commands/npm-prune) |
| 215 | - [npm outdated](/cli/v9/commands/npm-outdated) |
| 216 | - [npm update](/cli/v9/commands/npm-update) |