The npm list command can be used to list the currently installed packages in the present working directory. If no packages are installed in the present working directory, something like this should be returned.
~]# npm list
/home/john.doe
└── (empty)
The npm --global list command can be used to list the packages that are installed in the default installation of Node.js.
~]# npm list --global
/usr/local/bin/node-v20.10.0-linux-x64/lib
├── @elastic/synthetics@1.11.0
├── corepack@0.22.0
└── npm@10.2.3
Let's install a package, Sails in this example. Since the --global flag was not used, the Sails package will be installed in the present working directory.
npm install sails
This should create two files and a directory in the present working directory.
~]# ls --long
drwxr-xr-x 171 john.doe users 8192 Aug 6 22:28 node_modules
-rw-r--r-- 1 john.doe users 50 Aug 6 22:28 package.json
-rw-r--r-- 1 john.doe users 147873 Aug 6 22:28 package-lock.json
And now npm list should show that Sails is an installed package in the present working directory.
]$ npm list
/home/john.doe
└── sails@1.5.11
Let's install a package, @elastic/synthetics in this example. Since the --global flag is being used, the @elastic/synthetics package will be installed in the default installation of Node.js.
npm install --global @elastic/synthetics
The npm list --global command can be used to list packages that were installed using the --global flag.
~]# npm list --global
/usr/local/bin/node-v20.10.0-linux-x64/lib
├── @elastic/synthetics@1.11.0
├── corepack@0.22.0
└── npm@10.2.3
Did you find this article helpful?
If so, consider buying me a coffee over at