乐闻世界logo
搜索文章和话题

How to list npm user-installed packages

1个答案

1

To list the npm packages successfully installed by a user in their local environment, follow these steps:

  1. Open the command line interface.

  2. Navigate to the project's root directory using the cd command to ensure you're viewing the dependencies for the specific project. If you want to view globally installed packages, skip this step.

  3. Run the following commands:

    • To view locally installed packages for the project:
      sh
      npm list
    • To view globally installed packages:
      sh
      npm list -g --depth=0
      This command lists top-level globally installed packages (i.e., excluding their dependencies). The --depth=0 parameter ensures only top-level packages are displayed, not all dependencies.
  4. After executing the command, the terminal outputs a tree structure showing all installed packages and their versions.

For example, running npm list in a project containing express and lodash might produce:

plaintext
project-name@1.0.0 /path/to/project-name ├── express@4.17.1 └── lodash@4.17.20

This confirms successful installation of express v4.17.1 and lodash v4.17.20.

Additional parameters can customize the output:

  • --prod to show only production dependencies.
  • --dev to show only development dependencies.
  • --json to output results in JSON format.

These commands and parameters help any npm user quickly inspect installed package information.

2024年6月29日 12:07 回复

你的答案