DEV Community

Camille Hodoul
Camille Hodoul

Posted on • Originally published at camillehdl.dev

1 1

Update to the latest version of many npm dependencies at once

I couldn't find a npm command to update a subset of my dependencies to their latest version based on a name pattern, so here's a one-liner to do it with pipes and awk (to be modified for your needs).

In this example, I want to update all the dependencies containing the string "babel".

npm outdated |awk 'BEGIN{OFS="@"} $1 ~ /babel/ { print $1, "latest" }'| xargs npm install
Enter fullscreen mode Exit fullscreen mode

Explanation of each command

npm outdated lists your outdated dependencies.

awk:

  • BEGIN{OFS="@"} sets @ as the output field separator (will be used by print)
  • $1 ~ /babel/ will match the lines containing "babel" in their first column
  • { print $1, "latest" } will output each selected lines concatenated with "latest" (using "@" as the OFS)

xargs npm install will give the output of awk as input arguments to npm install, like so : npm install dependency1@latest dependency2@latest ...

Tweak it

The beauty of the command line: you could tweak this for different dependency managers, such as Composer for PHP.

Sentry blog image

Identify what makes your TTFB high so you can fix it

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

Read more

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay