One-liner to update npm dependency packages to the latest version using jq

Takuya Matsuyama - Feb 14 '20 - - Dev Community

If you have jq, a lightweight and flexible command-line JSON processor, installed in your computer, it's easy to manipulate the command to update dependencies to the latest version at once.

Update dependencies

Check:

cat package.json | jq -r '.dependencies | keys | join("\\n")'
Enter fullscreen mode Exit fullscreen mode

Perform installing:

cat package.json | jq -r '.dependencies | keys | map(. + "@latest") | join(" ")' | xargs npm i
Enter fullscreen mode Exit fullscreen mode

Update devDependencies

cat package.json | jq -r '.devDependencies | keys | map(. + "@latest") | join(" ")' | xargs npm i
Enter fullscreen mode Exit fullscreen mode

Follow me online

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .