📜  npm list (1)

📅  最后修改于: 2023-12-03 15:33:13.023000             🧑  作者: Mango

npm list

npm list is a command in npm that displays a tree of all the installed packages and their dependencies in a project. This command is very useful for developers to understand the structure of their project's dependencies and the versions of each package.

Usage

To use npm list, open the terminal and navigate to the root directory of your project, then run the following command:

npm list

This will display a tree of all the installed packages in your project, starting from the root directory.

You can also use npm list to display specific information about a package and its dependencies. For example, to display the dependencies of a specific package, run the following command:

npm list <package-name>

This will display the tree of the specified package and its dependencies.

Output

The output generated by npm list includes the package name, version number, and all the dependencies required by that package. The tree structure is denoted by indentation, with each level of indentation representing a level in the dependency hierarchy.

Here is an example of the output generated by npm list:

├─ express@4.17.1
│  ├─ accepts@1.3.7
│  ├─ array-flatten@1.1.1
│  ├─ body-parser@1.19.0
│  ├─ content-disposition@0.5.3
│  ├─ content-type@1.0.4
│  ├─ cookie@0.4.0
│  ├─ cookie-parser@1.4.5
│  ├─ debug@2.6.9
│  ├─ depd@1.1.2
│  ├─ encodeurl@1.0.2
│  ├─ escape-html@1.0.3
│  ├─ etag@1.8.1
│  ├─ finalhandler@1.1.2
│  ├─ fresh@0.5.2
│  ├─ merge-descriptors@1.0.1
│  ├─ methods@1.1.2
│  ├─ on-finished@2.3.0
│  ├─ parseurl@1.3.3
│  ├─ path-to-regexp@0.1.7
│  ├─ proxy-addr@2.0.7
│  ├─ qs@6.7.0
│  ├─ range-parser@1.2.1
│  ├─ safe-buffer@5.1.2
│  ├─ send@0.17.1
│  ├─ serve-static@1.14.1
│  ├─ setprototypeof@1.1.1
│  ├─ statuses@1.5.0
│  ├─ type-is@1.6.18
│  ├─ utils-merge@1.0.1
│  └─ vary@1.1.2
Options

npm list provides several options to customize the output:

  • -g: displays the globally installed packages instead of local packages
  • --depth <number>: limits the depth of the tree to a specified number
  • --json: outputs the tree information in JSON format
Conclusion

As a developer, npm list is a very useful command to understand the dependencies in your project and troubleshoot any issues related to packages. By using npm list, you can quickly visualize the hierarchy of packages and their dependencies, making it easier to spot and resolve any conflicts.