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
+-- browserify@16.2.2
`-- react-native-cli@2.0.1

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
+-- browserify@16.2.2
| +-- assert@1.4.1
| | `-- util@0.10.3
| |   `-- inherits@2.0.1
| +-- browser-pack@6.1.0
| | +-- combine-source-map@0.8.0
| | | +-- convert-source-map@1.1.3
| | | +-- inline-source-map@0.6.2
| | | | `-- source-map@0.5.7 deduped
| | | +-- lodash.memoize@3.0.4
| | | `-- source-map@0.5.7
| | +-- defined@1.0.0 deduped
| | +-- JSONStream@1.3.3 deduped
| | +-- safe-buffer@5.1.2
| | +-- through2@2.0.3 deduped
| | `-- umd@3.0.3
| +-- browser-resolve@1.11.3
| | `-- resolve@1.1.7
| +-- browserify-zlib@0.2.0
| | `-- pako@1.0.6
| +-- buffer@5.1.0
| | +-- base64-js@1.3.0
| | `-- ieee754@1.1.12
...
... -- purposely truncated --
...
`-- react-native-cli@2.0.1
  +-- chalk@1.1.3
  | +-- ansi-styles@2.2.1
  | +-- escape-string-regexp@1.0.5
  | +-- has-ansi@2.0.0
  | | `-- ansi-regex@2.1.1
  | +-- strip-ansi@3.0.1
  | | `-- ansi-regex@2.1.1 deduped
  | `-- supports-color@2.0.0
  +-- minimist@1.2.0
  +-- prompt@0.2.14
  | +-- pkginfo@0.4.1
  | +-- read@1.0.7
  | | `-- mute-stream@0.0.7
  | +-- revalidator@0.1.8
  | +-- utile@0.2.1
  | | +-- async@0.2.10
  | | +-- deep-equal@1.0.1
  | | +-- i@0.3.6
  | | +-- mkdirp@0.5.1
  | | | `-- minimist@0.0.8
  | | +-- ncp@0.4.2
  | | `-- rimraf@2.6.2
...
... -- 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

> spawn-sync@1.0.15 postinstall C:\Users\Dariawan\AppData\Roaming\npm\node_modules\generator-jhipster\node_modules\spawn-sync
> node postinstall

+ generator-jhipster@5.8.2
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
+-- browserify@16.2.2
+-- generator-jhipster@5.8.2
`-- react-native-cli@2.0.1