Member-only story
8 Key Npm and Yarn Commands To Master
Master the npm and yarn CLI

As JavaScript developers, we tend to spend a great deal of time managing our dependencies. Currently, the most used tools for that are yarn
and npm
. All of which are using the npm
repository.
By learning commands we can become more productive. We won’t need to leave the CLI to do trivial tasks. Both package manager tools have powerful commands that can get nearly every job done.
In this article, we will be looking at the top eight productive commands that we can use from our yarn/npm
CLI.
1. Packages Listing
We can install npm
packages globally. However, it is challenging to understand which libraries are installed in our machine library. We might want to do a cleanup and delete the ones that we are not using.
By using the list/ls
command we can use to inspect the installed dependencies. We can inspect the local and the global ones.
Doing cleanup will become a simple task by knowing how to use this command.
Usage
yarn list [--depth] [--pattern]npm ls [[<@scope>/]<pkg> ...]npm list [[<@scope>/]<pkg> ...]
Examples
# list all directory deps
npm list# list all the global deps
npm list -g# list only first level of deps
npm list -g --depth 0# list the dependencies 4 levels deep
npm list -g --depth 4# yarn is slightly different
yarn list --pattern gulp
Example of running the command on my machine:

2. Package Presence
This command will identify why your package has been installed. It is because of being a direct dependency? Perhaps other packages depend on it?
With this CLI command, you will easily understand why your package manager installed it.