2

I'm struggling to find a way to update all npm packages in one go, some articles suggest that package.json file should be edited where all version numbers need to be changed to * therefore forcing node to grab latest versions, but others state that such method is not considered good. Ideally, I want to find a command line option for this.

Ilja
  • 40,784
  • 74
  • 242
  • 455

5 Answers5

3

npm outdated is the command that you want to run to find all of the packages that are not up-to-date. You could pipe the output of npm output -json into a file and then iterate over the JSON to install the latest versions of the packages.

Zany Cadence
  • 171
  • 1
  • 6
2

You can try these one-liners.

Update all dependencies:

$ npm out --long --parseable |grep 'dependencies$' |cut -d: -f4 |xargs npm install --save

Update all devDependencies:

$ npm out --long --parseable |grep 'devDependencies$' |cut -d: -f4 |xargs npm install --save-dev

Keep in mind though that this is not usually a good idea as you might have to change something in the process of upgrading a package. If your project has many dependencies it is better to update them one by one or in small groups and run tests frequently.

eush77
  • 3,700
  • 1
  • 22
  • 30
2

One simple step:

$ npm i -g npm-check-updates && ncu -a && npm i

This will set all of your packages in package.json to the latest version.

Matt
  • 30,192
  • 23
  • 73
  • 87
0

For a single module you could try npm install --save module@latest That would change package.json too. You could write a shell script or script in nodejs to iterate though package.json and update all of the modules.

ajbisberg
  • 16
  • 2
0

Recursive update of all modules can performed with npm update:

  • for locally installed modules: npm update --depth 9999 --dev
  • for globally installed modules: npm update --depth 9999 --dev -g

A ready-to-use NPM-script to update all Node.js modules with all its dependencies:
How to update all Node.js modules automatically?

Mike
  • 12,690
  • 24
  • 87
  • 142