brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: npm ls --depth=0 lists only the packages you installed yourself

Tools
~/tips/tip-javascript-npm-ls-depth-0

npm ls --depth=0

Shows the top-level dependencies of a project without the long tree of dependencies below them.

A node_modules folder can hold hundreds of packages, and you installed a handful of them. This command shows that handful.

npm ls --depth=0
npm ls --depth=0 --global

npm ls prints the installed packages as a tree. The npm documentation describes --depth as the depth to go when recursing packages. Its default is 1 without --all, so recent npm versions already stop early, but --depth=0 is the way to show only the direct dependencies of the project itself.

With --global (or -g) the command looks at the globally installed packages instead, in the prefix folder. That is the quick way to see which command-line tools you installed with npm install -g, without the dependencies of each of them.

You can also ask about a single package, for example npm ls express, to see where it sits in the tree and which version is in use. That is useful when two versions of the same package are pulled in by different parents.

The docs say npm ls also prints extraneous, missing and invalid packages. So it doubles as a check that what is in node_modules matches what package.json asks for.

The caveat is that depth 0 hides what you most want to know when something breaks, because the problem is often a dependency of a dependency. For that, raise the depth or use npm ls --all to see everything.

Further reading: npm documentation: npm ls

More Tools tips shuf -n 3 films.txt xmllint --format feed.xml pdftotext -layout invoice.pdf invoice.txt qrencode -t ANSIUTF8 'https://example.com/a/long/path?id=12345' where python All Tools tips (14) All topics

Link