npm - Get List of Globally Installed Packages

How to check the list of globally installed npm packages in our workstation? We can use command:

npm list -g --depth 0

Let's run it, and we will get something similar like this:

C:\Users\Dariawan>npm list -g --depth 0
C:\Users\Dariawan\AppData\Roaming\npm
+-- [email protected]
`-- [email protected]

Here the explanation of the command:

  • npm: Node Package Manager command line tool - package manager for the JavaScript programming language
  • list -g: display a tree of packages found in the user’s folders (without the -g option, it will list down packages in the current directory)
  • --depth 0: don't include package’s dependencies in the tree view

if we run npm list -g without --depth 0, we will get all dependencies printed in treeview:

C:\Users\Dariawan\AppData\Roaming\npm
+-- [email protected]
| +-- [email protected]
| | `-- [email protected]
| |   `-- [email protected]
| +-- [email protected]
| | +-- [email protected]
| | | +-- [email protected]
| | | +-- [email protected]
| | | | `-- [email protected] deduped
| | | +-- [email protected]
| | | `-- [email protected]
| | +-- [email protected] deduped
| | +-- [email protected] deduped
| | +-- [email protected]
| | +-- [email protected] deduped
| | `-- [email protected]
| +-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| | +-- [email protected]
| | `-- [email protected]
...
... -- purposely truncated --
...
`-- [email protected]
  +-- [email protected]
  | +-- [email protected]
  | +-- [email protected]
  | +-- [email protected]
  | | `-- [email protected]
  | +-- [email protected]
  | | `-- [email protected] deduped
  | `-- [email protected]
  +-- [email protected]
  +-- [email protected]
  | +-- [email protected]
  | +-- [email protected]
  | | `-- [email protected]
  | +-- [email protected]
  | +-- [email protected]
  | | +-- [email protected]
  | | +-- [email protected]
  | | +-- [email protected]
  | | +-- [email protected]
  | | | `-- [email protected]
  | | +-- [email protected]
  | | `-- [email protected]
...
... -- purposely truncated --
...

No npm/Node.js?

npm now is the de-facto standard package manager for the JavaScript programming language. It's installed together with Node.js. If you are using Windows environment, I suggest to install Chocolatey - the package manager for Windows. And from Chocolatey, you can install Node.js. My suggestion, install the LTS version:

C:\WINDOWS\system32>choco install nodejs-lts
Chocolatey v0.10.8
Installing the following packages:
nodejs-lts
By installing you accept licenses for the packages.
Progress: Downloading nodejs-lts 10.15.3... 100%

nodejs-lts v10.15.3 [Approved]
nodejs-lts package files install completed. Performing other installation steps.
The package nodejs-lts wants to run 'chocolateyinstall.ps1'.
Note: If you don't run this script, the installation will fail.
Note: To confirm automatically next time, use '-y' or consider:
choco feature enable -n allowGlobalConfirmation
Do you want to run the script?([Y]es/[N]o/[P]rint): Y

Installing 64 bit version
Installing nodejs-lts...
nodejs-lts has been installed.
  nodejs-lts may be able to be automatically uninstalled.
Environment Vars (like PATH) have changed. Close/reopen your shell to
 see the changes (or in powershell/cmd.exe just type `refreshenv`).
 The install of nodejs-lts was successful.
  Software installed as 'MSI', install location is likely default.

Chocolatey installed 1/1 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Test your Node and npm version:

C:\Users\Dariawan>node -v
v9.4.0

C:\Users\Dariawan>npm -v
6.4.1

Now your npm is ready.

Installing Packages using npm

Use npm install to install npm package to your workstation. Use -g to install it globally as below example:

C:\WINDOWS\system32>npm install -g generator-jhipster
C:\Users\Dariawan\AppData\Roaming\npm\jhipster -> C:\Users\Dariawan\AppData\Roaming\npm\node_modules\generator-jhipster\cli\jhipster.js

> [email protected] postinstall C:\Users\Dariawan\AppData\Roaming\npm\node_modules\generator-jhipster\node_modules\spawn-sync
> node postinstall

+ [email protected]
added 513 packages from 330 contributors in 113.956s

When we list down our globally installed packages, now we found generator-jhipster is in the list

C:\Users\Dariawan>npm list -g --depth 0
C:\Users\Dariawan\AppData\Roaming\npm
+-- [email protected]
+-- [email protected]
`-- [email protected]