February 2023
3 minute read time
Hidden gems in npm
Martin Torp
By Martin Torp
Cofounder of Coana
PhD in Computer Science

<m>You may be familiar with npm commands like `npm install`, `npm ci`, and `npm uninstall`.
However, did you know that there are several other useful commands that you should know as a maintainer of npm projects?
Here are a few of my favorites:</m>

<m>**Find versions of your dependencies:**
If you quickly need to see which packages you use and their versions, then use `npm ls`.
You can also specify a package name if you only need information about a specific package, like this: `npm ls jest`.
To include data on your indirect dependencies as well, you can pass the `--all` flag: `npm ls chalk --all`.</m>

<m> **Check for outdated dependencies:**
The `npm outdated` command will show you how outdated your dependencies are.
Updates that fall within the SemVer[^1] constraints (like minor and patch updates when using the ^ constraints) will be colored red, while other updates (such as major updates for ^ SemVer constraints) will be colored yellow.
To update to the latest version that satisfies the SemVer constraint, you can use the `npm update` command: For example,`npm update chalk`.</m>

<m>**Examine a package before installing:**
Use the view command get detailed metadata about a specific package. For example, `npm view chalk`.
You can also query for detailed information about specific types of metadata like this: `npm view lodash versions` or `npm view express dependencies`.</m>

<m>**Make edits to a dependency:**
Use the `npm edit` command to edit the installed version of a dependency in your default editor. For example, `npm edit chalk`.
The npm edit command is conveniently combined with [patch-package](https://www.npmjs.com/package/patch-package), which allows you to create a patch file with your edits so that they can be persisted in your repository.</m>

<m>These commands should help you better maintain your npm projects. Give them a try and see how they can improve your workflow.</m>

<m>[^1]: Read our quick introduction to semantic versioning [here](https://www.coana.tech/post/understanding-semantic-versioning-a-guide-for-npm-developers-part-1) </m>

Questions or opinions?

Feel free to reach out to us by email or through our Slack Community anytime. We'd love to hear from you.

Join waitlist

Sign up to get notified about future Coana future launches.