11cb0ef41Sopenharmony_ci--- 21cb0ef41Sopenharmony_cititle: npm-ls 31cb0ef41Sopenharmony_cisection: 1 41cb0ef41Sopenharmony_cidescription: List installed packages 51cb0ef41Sopenharmony_ci--- 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci### Synopsis 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci```bash 101cb0ef41Sopenharmony_cinpm ls <package-spec> 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_cialias: list 131cb0ef41Sopenharmony_ci``` 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci### Description 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciThis command will print to stdout all the versions of packages that are 181cb0ef41Sopenharmony_ciinstalled, as well as their dependencies when `--all` is specified, in a 191cb0ef41Sopenharmony_citree structure. 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ciNote: to get a "bottoms up" view of why a given package is included in the 221cb0ef41Sopenharmony_citree at all, use [`npm explain`](/commands/npm-explain). 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ciPositional arguments are `name@version-range` identifiers, which will limit 251cb0ef41Sopenharmony_cithe results to only the paths to the packages named. Note that nested 261cb0ef41Sopenharmony_cipackages will *also* show the paths to the specified packages. For 271cb0ef41Sopenharmony_ciexample, running `npm ls promzard` in npm's source tree will show: 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci```bash 301cb0ef41Sopenharmony_cinpm@10.5.0 /path/to/npm 311cb0ef41Sopenharmony_ci└─┬ init-package-json@0.0.4 321cb0ef41Sopenharmony_ci └── promzard@0.1.5 331cb0ef41Sopenharmony_ci``` 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ciIt will print out extraneous, missing, and invalid packages. 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ciIf a project specifies git urls for dependencies these are shown 381cb0ef41Sopenharmony_ciin parentheses after the `name@version` to make it easier for users to 391cb0ef41Sopenharmony_cirecognize potential forks of a project. 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ciThe tree shown is the logical dependency tree, based on package 421cb0ef41Sopenharmony_cidependencies, not the physical layout of your `node_modules` folder. 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ciWhen run as `ll` or `la`, it shows extended information by default. 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci### Note: Design Changes Pending 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ciThe `npm ls` command's output and behavior made a _ton_ of sense when npm 491cb0ef41Sopenharmony_cicreated a `node_modules` folder that naively nested every dependency. In 501cb0ef41Sopenharmony_cisuch a case, the logical dependency graph and physical tree of packages on 511cb0ef41Sopenharmony_cidisk would be roughly identical. 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_ciWith the advent of automatic install-time deduplication of dependencies in 541cb0ef41Sopenharmony_cinpm v3, the `ls` output was modified to display the logical dependency 551cb0ef41Sopenharmony_cigraph as a tree structure, since this was more useful to most users. 561cb0ef41Sopenharmony_ciHowever, without using `npm ls -l`, it became impossible to show _where_ a 571cb0ef41Sopenharmony_cipackage was actually installed much of the time! 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ciWith the advent of automatic installation of `peerDependencies` in npm v7, 601cb0ef41Sopenharmony_cithis gets even more curious, as `peerDependencies` are logically 611cb0ef41Sopenharmony_ci"underneath" their dependents in the dependency graph, but are always 621cb0ef41Sopenharmony_ciphysically at or above their location on disk. 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ciAlso, in the years since npm got an `ls` command (in version 0.0.2!), 651cb0ef41Sopenharmony_cidependency graphs have gotten much larger as a general rule. Therefore, in 661cb0ef41Sopenharmony_ciorder to avoid dumping an excessive amount of content to the terminal, `npm 671cb0ef41Sopenharmony_cils` now only shows the _top_ level dependencies, unless `--all` is 681cb0ef41Sopenharmony_ciprovided. 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ciA thorough re-examination of the use cases, intention, behavior, and output 711cb0ef41Sopenharmony_ciof this command, is currently underway. Expect significant changes to at 721cb0ef41Sopenharmony_cileast the default human-readable `npm ls` output in npm v8. 731cb0ef41Sopenharmony_ci 741cb0ef41Sopenharmony_ci### Configuration 751cb0ef41Sopenharmony_ci 761cb0ef41Sopenharmony_ci#### `all` 771cb0ef41Sopenharmony_ci 781cb0ef41Sopenharmony_ci* Default: false 791cb0ef41Sopenharmony_ci* Type: Boolean 801cb0ef41Sopenharmony_ci 811cb0ef41Sopenharmony_ciWhen running `npm outdated` and `npm ls`, setting `--all` will show all 821cb0ef41Sopenharmony_cioutdated or installed packages, rather than only those directly depended 831cb0ef41Sopenharmony_ciupon by the current project. 841cb0ef41Sopenharmony_ci 851cb0ef41Sopenharmony_ci 861cb0ef41Sopenharmony_ci 871cb0ef41Sopenharmony_ci#### `json` 881cb0ef41Sopenharmony_ci 891cb0ef41Sopenharmony_ci* Default: false 901cb0ef41Sopenharmony_ci* Type: Boolean 911cb0ef41Sopenharmony_ci 921cb0ef41Sopenharmony_ciWhether or not to output JSON data, rather than the normal output. 931cb0ef41Sopenharmony_ci 941cb0ef41Sopenharmony_ci* In `npm pkg set` it enables parsing set values with JSON.parse() before 951cb0ef41Sopenharmony_ci saving them to your `package.json`. 961cb0ef41Sopenharmony_ci 971cb0ef41Sopenharmony_ciNot supported by all npm commands. 981cb0ef41Sopenharmony_ci 991cb0ef41Sopenharmony_ci 1001cb0ef41Sopenharmony_ci 1011cb0ef41Sopenharmony_ci#### `long` 1021cb0ef41Sopenharmony_ci 1031cb0ef41Sopenharmony_ci* Default: false 1041cb0ef41Sopenharmony_ci* Type: Boolean 1051cb0ef41Sopenharmony_ci 1061cb0ef41Sopenharmony_ciShow extended information in `ls`, `search`, and `help-search`. 1071cb0ef41Sopenharmony_ci 1081cb0ef41Sopenharmony_ci 1091cb0ef41Sopenharmony_ci 1101cb0ef41Sopenharmony_ci#### `parseable` 1111cb0ef41Sopenharmony_ci 1121cb0ef41Sopenharmony_ci* Default: false 1131cb0ef41Sopenharmony_ci* Type: Boolean 1141cb0ef41Sopenharmony_ci 1151cb0ef41Sopenharmony_ciOutput parseable results from commands that write to standard output. For 1161cb0ef41Sopenharmony_ci`npm search`, this will be tab-separated table format. 1171cb0ef41Sopenharmony_ci 1181cb0ef41Sopenharmony_ci 1191cb0ef41Sopenharmony_ci 1201cb0ef41Sopenharmony_ci#### `global` 1211cb0ef41Sopenharmony_ci 1221cb0ef41Sopenharmony_ci* Default: false 1231cb0ef41Sopenharmony_ci* Type: Boolean 1241cb0ef41Sopenharmony_ci 1251cb0ef41Sopenharmony_ciOperates in "global" mode, so that packages are installed into the `prefix` 1261cb0ef41Sopenharmony_cifolder instead of the current working directory. See 1271cb0ef41Sopenharmony_ci[folders](/configuring-npm/folders) for more on the differences in behavior. 1281cb0ef41Sopenharmony_ci 1291cb0ef41Sopenharmony_ci* packages are installed into the `{prefix}/lib/node_modules` folder, instead 1301cb0ef41Sopenharmony_ci of the current working directory. 1311cb0ef41Sopenharmony_ci* bin files are linked to `{prefix}/bin` 1321cb0ef41Sopenharmony_ci* man pages are linked to `{prefix}/share/man` 1331cb0ef41Sopenharmony_ci 1341cb0ef41Sopenharmony_ci 1351cb0ef41Sopenharmony_ci 1361cb0ef41Sopenharmony_ci#### `depth` 1371cb0ef41Sopenharmony_ci 1381cb0ef41Sopenharmony_ci* Default: `Infinity` if `--all` is set, otherwise `1` 1391cb0ef41Sopenharmony_ci* Type: null or Number 1401cb0ef41Sopenharmony_ci 1411cb0ef41Sopenharmony_ciThe depth to go when recursing packages for `npm ls`. 1421cb0ef41Sopenharmony_ci 1431cb0ef41Sopenharmony_ciIf not set, `npm ls` will show only the immediate dependencies of the root 1441cb0ef41Sopenharmony_ciproject. If `--all` is set, then npm will show all dependencies by default. 1451cb0ef41Sopenharmony_ci 1461cb0ef41Sopenharmony_ci 1471cb0ef41Sopenharmony_ci 1481cb0ef41Sopenharmony_ci#### `omit` 1491cb0ef41Sopenharmony_ci 1501cb0ef41Sopenharmony_ci* Default: 'dev' if the `NODE_ENV` environment variable is set to 1511cb0ef41Sopenharmony_ci 'production', otherwise empty. 1521cb0ef41Sopenharmony_ci* Type: "dev", "optional", or "peer" (can be set multiple times) 1531cb0ef41Sopenharmony_ci 1541cb0ef41Sopenharmony_ciDependency types to omit from the installation tree on disk. 1551cb0ef41Sopenharmony_ci 1561cb0ef41Sopenharmony_ciNote that these dependencies _are_ still resolved and added to the 1571cb0ef41Sopenharmony_ci`package-lock.json` or `npm-shrinkwrap.json` file. They are just not 1581cb0ef41Sopenharmony_ciphysically installed on disk. 1591cb0ef41Sopenharmony_ci 1601cb0ef41Sopenharmony_ciIf a package type appears in both the `--include` and `--omit` lists, then 1611cb0ef41Sopenharmony_ciit will be included. 1621cb0ef41Sopenharmony_ci 1631cb0ef41Sopenharmony_ciIf the resulting omit list includes `'dev'`, then the `NODE_ENV` environment 1641cb0ef41Sopenharmony_civariable will be set to `'production'` for all lifecycle scripts. 1651cb0ef41Sopenharmony_ci 1661cb0ef41Sopenharmony_ci 1671cb0ef41Sopenharmony_ci 1681cb0ef41Sopenharmony_ci#### `include` 1691cb0ef41Sopenharmony_ci 1701cb0ef41Sopenharmony_ci* Default: 1711cb0ef41Sopenharmony_ci* Type: "prod", "dev", "optional", or "peer" (can be set multiple times) 1721cb0ef41Sopenharmony_ci 1731cb0ef41Sopenharmony_ciOption that allows for defining which types of dependencies to install. 1741cb0ef41Sopenharmony_ci 1751cb0ef41Sopenharmony_ciThis is the inverse of `--omit=<type>`. 1761cb0ef41Sopenharmony_ci 1771cb0ef41Sopenharmony_ciDependency types specified in `--include` will not be omitted, regardless of 1781cb0ef41Sopenharmony_cithe order in which omit/include are specified on the command-line. 1791cb0ef41Sopenharmony_ci 1801cb0ef41Sopenharmony_ci 1811cb0ef41Sopenharmony_ci 1821cb0ef41Sopenharmony_ci#### `link` 1831cb0ef41Sopenharmony_ci 1841cb0ef41Sopenharmony_ci* Default: false 1851cb0ef41Sopenharmony_ci* Type: Boolean 1861cb0ef41Sopenharmony_ci 1871cb0ef41Sopenharmony_ciUsed with `npm ls`, limiting output to only those packages that are linked. 1881cb0ef41Sopenharmony_ci 1891cb0ef41Sopenharmony_ci 1901cb0ef41Sopenharmony_ci 1911cb0ef41Sopenharmony_ci#### `package-lock-only` 1921cb0ef41Sopenharmony_ci 1931cb0ef41Sopenharmony_ci* Default: false 1941cb0ef41Sopenharmony_ci* Type: Boolean 1951cb0ef41Sopenharmony_ci 1961cb0ef41Sopenharmony_ciIf set to true, the current operation will only use the `package-lock.json`, 1971cb0ef41Sopenharmony_ciignoring `node_modules`. 1981cb0ef41Sopenharmony_ci 1991cb0ef41Sopenharmony_ciFor `update` this means only the `package-lock.json` will be updated, 2001cb0ef41Sopenharmony_ciinstead of checking `node_modules` and downloading dependencies. 2011cb0ef41Sopenharmony_ci 2021cb0ef41Sopenharmony_ciFor `list` this means the output will be based on the tree described by the 2031cb0ef41Sopenharmony_ci`package-lock.json`, rather than the contents of `node_modules`. 2041cb0ef41Sopenharmony_ci 2051cb0ef41Sopenharmony_ci 2061cb0ef41Sopenharmony_ci 2071cb0ef41Sopenharmony_ci#### `unicode` 2081cb0ef41Sopenharmony_ci 2091cb0ef41Sopenharmony_ci* Default: false on windows, true on mac/unix systems with a unicode locale, 2101cb0ef41Sopenharmony_ci as defined by the `LC_ALL`, `LC_CTYPE`, or `LANG` environment variables. 2111cb0ef41Sopenharmony_ci* Type: Boolean 2121cb0ef41Sopenharmony_ci 2131cb0ef41Sopenharmony_ciWhen set to true, npm uses unicode characters in the tree output. When 2141cb0ef41Sopenharmony_cifalse, it uses ascii characters instead of unicode glyphs. 2151cb0ef41Sopenharmony_ci 2161cb0ef41Sopenharmony_ci 2171cb0ef41Sopenharmony_ci 2181cb0ef41Sopenharmony_ci#### `workspace` 2191cb0ef41Sopenharmony_ci 2201cb0ef41Sopenharmony_ci* Default: 2211cb0ef41Sopenharmony_ci* Type: String (can be set multiple times) 2221cb0ef41Sopenharmony_ci 2231cb0ef41Sopenharmony_ciEnable running a command in the context of the configured workspaces of the 2241cb0ef41Sopenharmony_cicurrent project while filtering by running only the workspaces defined by 2251cb0ef41Sopenharmony_cithis configuration option. 2261cb0ef41Sopenharmony_ci 2271cb0ef41Sopenharmony_ciValid values for the `workspace` config are either: 2281cb0ef41Sopenharmony_ci 2291cb0ef41Sopenharmony_ci* Workspace names 2301cb0ef41Sopenharmony_ci* Path to a workspace directory 2311cb0ef41Sopenharmony_ci* Path to a parent workspace directory (will result in selecting all 2321cb0ef41Sopenharmony_ci workspaces within that folder) 2331cb0ef41Sopenharmony_ci 2341cb0ef41Sopenharmony_ciWhen set for the `npm init` command, this may be set to the folder of a 2351cb0ef41Sopenharmony_ciworkspace which does not yet exist, to create the folder and set it up as a 2361cb0ef41Sopenharmony_cibrand new workspace within the project. 2371cb0ef41Sopenharmony_ci 2381cb0ef41Sopenharmony_ciThis value is not exported to the environment for child processes. 2391cb0ef41Sopenharmony_ci 2401cb0ef41Sopenharmony_ci#### `workspaces` 2411cb0ef41Sopenharmony_ci 2421cb0ef41Sopenharmony_ci* Default: null 2431cb0ef41Sopenharmony_ci* Type: null or Boolean 2441cb0ef41Sopenharmony_ci 2451cb0ef41Sopenharmony_ciSet to true to run the command in the context of **all** configured 2461cb0ef41Sopenharmony_ciworkspaces. 2471cb0ef41Sopenharmony_ci 2481cb0ef41Sopenharmony_ciExplicitly setting this to false will cause commands like `install` to 2491cb0ef41Sopenharmony_ciignore workspaces altogether. When not set explicitly: 2501cb0ef41Sopenharmony_ci 2511cb0ef41Sopenharmony_ci- Commands that operate on the `node_modules` tree (install, update, etc.) 2521cb0ef41Sopenharmony_ciwill link workspaces into the `node_modules` folder. - Commands that do 2531cb0ef41Sopenharmony_ciother things (test, exec, publish, etc.) will operate on the root project, 2541cb0ef41Sopenharmony_ci_unless_ one or more workspaces are specified in the `workspace` config. 2551cb0ef41Sopenharmony_ci 2561cb0ef41Sopenharmony_ciThis value is not exported to the environment for child processes. 2571cb0ef41Sopenharmony_ci 2581cb0ef41Sopenharmony_ci#### `include-workspace-root` 2591cb0ef41Sopenharmony_ci 2601cb0ef41Sopenharmony_ci* Default: false 2611cb0ef41Sopenharmony_ci* Type: Boolean 2621cb0ef41Sopenharmony_ci 2631cb0ef41Sopenharmony_ciInclude the workspace root when workspaces are enabled for a command. 2641cb0ef41Sopenharmony_ci 2651cb0ef41Sopenharmony_ciWhen false, specifying individual workspaces via the `workspace` config, or 2661cb0ef41Sopenharmony_ciall workspaces via the `workspaces` flag, will cause npm to operate only on 2671cb0ef41Sopenharmony_cithe specified workspaces, and not on the root project. 2681cb0ef41Sopenharmony_ci 2691cb0ef41Sopenharmony_ciThis value is not exported to the environment for child processes. 2701cb0ef41Sopenharmony_ci 2711cb0ef41Sopenharmony_ci#### `install-links` 2721cb0ef41Sopenharmony_ci 2731cb0ef41Sopenharmony_ci* Default: false 2741cb0ef41Sopenharmony_ci* Type: Boolean 2751cb0ef41Sopenharmony_ci 2761cb0ef41Sopenharmony_ciWhen set file: protocol dependencies will be packed and installed as regular 2771cb0ef41Sopenharmony_cidependencies instead of creating a symlink. This option has no effect on 2781cb0ef41Sopenharmony_ciworkspaces. 2791cb0ef41Sopenharmony_ci 2801cb0ef41Sopenharmony_ci 2811cb0ef41Sopenharmony_ci 2821cb0ef41Sopenharmony_ci### See Also 2831cb0ef41Sopenharmony_ci 2841cb0ef41Sopenharmony_ci* [package spec](/using-npm/package-spec) 2851cb0ef41Sopenharmony_ci* [npm explain](/commands/npm-explain) 2861cb0ef41Sopenharmony_ci* [npm config](/commands/npm-config) 2871cb0ef41Sopenharmony_ci* [npmrc](/configuring-npm/npmrc) 2881cb0ef41Sopenharmony_ci* [npm folders](/configuring-npm/folders) 2891cb0ef41Sopenharmony_ci* [npm explain](/commands/npm-explain) 2901cb0ef41Sopenharmony_ci* [npm install](/commands/npm-install) 2911cb0ef41Sopenharmony_ci* [npm link](/commands/npm-link) 2921cb0ef41Sopenharmony_ci* [npm prune](/commands/npm-prune) 2931cb0ef41Sopenharmony_ci* [npm outdated](/commands/npm-outdated) 2941cb0ef41Sopenharmony_ci* [npm update](/commands/npm-update) 295