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.
- 40,784
- 74
- 242
- 455
-
`npm outdated` might help you – Explosion Pills Nov 05 '15 at 19:30
-
@ExplosionPills doesn't return me anything, just new prompt to enter commands, is it doing something in the background? – Ilja Nov 05 '15 at 19:31
-
https://stackoverflow.com/questions/34202617/how-to-completely-update-all-node-js-modules-to-the-latest-version/34295664#34295664 – Mike Sep 23 '18 at 06:49
5 Answers
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.
- 171
- 1
- 6
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.
- 3,700
- 1
- 22
- 30
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.
- 30,192
- 23
- 73
- 87
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.
- 16
- 2
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?
- 12,690
- 24
- 87
- 142