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.

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more