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.

- 44,142
- 92
- 275
- 498
-
`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
-
best answer: https://stackoverflow.com/a/16074029/6908282 – Gangula Jun 11 '23 at 21:55
6 Answers
One simple step:
$ npm i -g npm-check-updates && ncu -u && npm i
This will install ncu, use it set all of your packages in package.json
to the latest version and finally apply the updates.

- 364
- 3
- 14

- 33,328
- 25
- 83
- 97
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.

- 219
- 2
- 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,870
- 1
- 23
- 30
npm outdated -p | cut -d ':' -f 5 | xargs npm install
Explaination
npm outdated -p
: get a list of outdated packages and put them into parseable lines
Example line:
<project_path>\node_modules\<package_name>:<package_name>@<wanted_version>:<package_name>@<current_version>:<package_name>@<latest_version>:<module_name>
cut -d ':' -f 5
: get the latest version
xargs npm install
: install package by package

- 11
- 1
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?

- 14,010
- 29
- 101
- 161