Skip to content

Instantly share code, notes, and snippets.

@jeff-french
Last active January 10, 2018 18:08
Show Gist options
  • Save jeff-french/4596198eedaa6cf833a9f63a3a4e47d7 to your computer and use it in GitHub Desktop.
Save jeff-french/4596198eedaa6cf833a9f63a3a4e47d7 to your computer and use it in GitHub Desktop.
Update all outdated npm packages

To update all packages that are returned by the npm outdated command to their latest version:

$ npm outdated | tail -n +2 | tr -s ' ' | cut -d ' ' -f1 | xargs -I {} npm up {}

Explaination

npm outdated: Lists all packages installed that are not at their latest version.

tail -n +2: start parsing the output of the previous command from the seccond line (cut off the headers from npm outdated)

tf -s '': since there are varying amounts of whitespace between some of the columns, squeeze it down to just one space between each column

cut -d ' ' -f1: split the previous output into columns on the "space" character and then print the first field

xargs -I {} npm up {}: run the npm up command for each line of the output and replace {} with the actual output (in this case the package name)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment