Explain Codes LogoExplain Codes Logo

How to list npm user-installed packages

javascript
npm
package-management
command-line-interfaces
Nikita BarsukovbyNikita Barsukov·Aug 21, 2024
TLDR

To list global npm packages use npm list -g --depth=0; for local packages, just eliminate -g in a project directory: npm list --depth=0.

Find global installations

For a neat display of all global packages, utilize:

npm list -g --depth=0

-g tag shows global packages while --depth=0 ensures we avoid digging into dependencies. Here, -g stands for global, not gravity...unfortunately.👨‍🚀

Locate package directory

Wish to know where these global residents chill out? Use npm root -g to take a peek at the global node_modules directory. Yes, even packages have a home.🏠

Update your global packages

Updating specific packages is as simple as npm update -g <package>. Want to carry out a mass update? Just type npm update -g. Buckle up, updates incoming!🚀

Identify outdated packages

To detect which packages are the "old ones," employ npm outdated -g --depth=0. This will list global packages due for an upgrade. Out with the old, in with the new!🎉

Visualization

If you consider your project as a garden, each package is a beautiful flower you've planted:

🌳🌱🌿 Your JavaScript Garden 🌿🌱🌳

To admire only your blossoms:

npm list --depth=0

The output? A floral display of your user-installed packages:

--depth=0 — our guard against angering the Bee Queen by plucking wild flowers.🐝

Employ a visual interface

npm-gui introduces zen to package management. Fire it up with:

npm-gui localhost:9000

Behold a GUI display of your project packages at localhost:9000. It's like visualizing the matrix!💻

Search for specific modules

Looking for a needle in a haystack? Combine npm list with grep:

npm list -g | grep <module_name>

It's the Where's Waldo? of the package world.🕵️‍♀️

Check versions on the fly

For the latest remote version of a module, type npm view <module_name> version. Discover all versions of a module with npm view <module_name> versions. This way, you can cradle newer versions like they're newborns!👶

Manage local project packages

List installed packages

To collate your locally installed packages, run:

npm list --depth=0

Differentiate local from global

Between global and local, where should packages reside? Global scope — tools/utilities, Local scope — project-specific dependencies. Don't mix match!❌

Remove unnecessary packages

Got an unused package? Give it the boot with:

npm uninstall <package_name>

For global packages, add the -g flag. Adios, unwanted packages!👋