npm - update all dependencies to latest version
In this article, we would like to show you how to update all dependencies to latest version in npm.
Quick solution:
npm update
or (using hard upgrade):
ncu -u && npm install
Where: ncu should be installed using npm install -g npm-check-updates
Embedded solution
Using this section you can update dependencies using embedded npm command.
Simple steps:
1. Check outdated dependencies using:
npm outdated
Note: you can ommit
npm outdatedcommand and just runnpm update.
2. Update outdated dependencies using:
npm update
Note:
The above solution will update:
- the packages in the
package.jsonandpackage-lock.jsonfiles,- the packages in the
node_modules/directory.
External solution
Using this section you can update dependencies using external ncu command. ncu should be installed using npm install -g npm-check-updates.
Simple steps:
1. Check outdated dependencies using:
npx ncu
Note: you can ommit
ncucommand and just runnpx ncu -u && npm install.
2. Update outdated dependencies using:
npx ncu -u && npm install
Hint:
npx ncu -uis equivalne fornpx npm-check-updates -u.
Note:
The above solution will update:
- the packages in the
package.jsonfile and then inpackage-lock.jsonfile,- the packages in the
node_modules/directory.