. Advertisement .
..3..
. Advertisement .
..4..
This article is tailored for all users who want to learn to list NPM global packages. In general, the most employed tactic is to use NPM list commands. But what are they, and how can you insert them to reach your goal? Check out our instructions below.
What Are NPM List Commands?
This list command will produce installed packages (and their distinctive dependences) of your current project. These outputs serve as tree structures to “stdout”.
npm list
Outputs:
PS D:\nodejs\npm-demo> npm list
[email protected] D:\nodejs\npm-demo
[email protected]
| +- - [email protected]
| | + - - [email protected]
| | - [email protected]
| | – - [email protected]
| + - - [email protected]
| + - - [email protected]
| | + - - [email protected]
| | +- - [email protected] deduped
| | + - - [email protected] deduped
| | +- - [email protected] deduped [email protected]
| | | +- - [email protected] deduped
| | | +- - [email protected]
| | | + - - [email protected] dedup
| | | + - - [email protected] deduped
| | | ' - - [email protected]
| | +-- [email protected]
| | | ' -- [email protected]
| | +-- [email protected] deduped
| | +-- as@6 7.8 deduned
How to List NPM Global Packages?
You can install NPM global packages by the “-g” or “–global” flag. That way, the system may use the package from your consoles. But how to list all of these globally installed packages on the system? Similarly, employ the “-g” NPM list command from the console:
npm list -g
# or
npm list --global
# for npm v6 and below
npm list -g --depth=0
The example below illustrates the command operation on a console:
$ npm list -g
/Users/nsebhastian/.nvm/versions/node/v16.3.0/lib
├── @vue/[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
Let’s examine this output. It is quite clear that the “NPM list” command also prints all locations where you installed the packages. Occasionally, other developers will recommend you to employ the config “–depth=0” in an “NPM list” command operation:
npm list -g --depth=0
The config “–depth=0” aims to conceal each package’s dependencies from its output. Still, if you use version 7 of the NPM, the list command will automatically do that by default. But if you want the version 7 system to showcase these dependencies, it is advisable to employ the config “-all”:
npm list -g --all
What will happen if you set up NPM packages in customized locations via the config “–prefix”? Then we suggest you employ that same config “–prefix” upon the list command operation.
Suppose you want to set up the express packages in a customized location, like this:
npm install express --prefix /Users/nsebhastian/Desktop/test/nodeWs
Insert the similar command “–prefix” upon calling an NPM command:
$ npm list --prefix /Users/nsebhastian/Desktop/test/nodeWs
[email protected] /Users/nsebhastian/Desktop/test/nodeWs
├── [email protected]
├── [email protected]
└── [email protected]
Conclusion
We have successfully instructed you to list NPM global packages. On some occasions, the system might produce the error: “Warning: To load an ES module, set “type”: “module”. Refer to this ITtutoria tutorial for optimal solutions.
Feel free to contact us if you still feel unsure, and good luck with your programming!
Leave a comment