To list the npm packages successfully installed by a user in their local environment, follow these steps:
-
Open the command line interface.
-
Navigate to the project's root directory using the
cdcommand to ensure you're viewing the dependencies for the specific project. If you want to view globally installed packages, skip this step. -
Run the following commands:
- To view locally installed packages for the project:
sh
npm list - To view globally installed packages:
This command lists top-level globally installed packages (i.e., excluding their dependencies). Theshnpm list -g --depth=0--depth=0parameter ensures only top-level packages are displayed, not all dependencies.
- To view locally installed packages for the project:
-
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:
plaintextproject-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:
--prodto show only production dependencies.--devto show only development dependencies.--jsonto output results in JSON format.
These commands and parameters help any npm user quickly inspect installed package information.