Better Programming

Advice for programmers.

Follow publication

Member-only story

8 Key Npm and Yarn Commands To Master

Jose Granja
Better Programming
Published in
5 min readMar 29, 2022
Capture by Author
Capture by Author

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:

Command capture taken by Author
Command capture taken by Author

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.

Usage

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Jose Granja
Jose Granja

Written by Jose Granja

Top Writer @Medium | 1M+ Views | Lead FE @Lingoda | I write weekly about web-development topics 📰 Support me at https://dioxmio.medium.com/membership 🙇

Responses (1)

Write a response