visit
The simplest way to update npm packages is to install npm-check-updates
, run npx ncu
, followed by npx ncu -u
to update the package.json followed by npm install
to update packages in package.lock
and node_modules.
When running npm outdated
you can get a list of packages that have available updates:
We can update individual packages by running npm update {package-name}
.
npm update sass
Enter fullscreen mode Exit fullscreen mode. Now if we run npm outdated
again we can (as seen in the image below) that the package was indeed updated. One thing to note is that while package.lock
was updated package.json
remains untouched.
Another option, that I find slightly more convenient, especially for more low-risk projects is using the npm-check-updates
package.
npm install -g npm-check-updates
Enter fullscreen mode Exit fullscreen mode.
npx ncu
Similar to npm outdated
this gives us a list of all available updates:
npx ncu -uf sass
Enter fullscreen mode Exit fullscreen mode
npm install
Now, if we run npx ncu
again we see the sass
package was updated:
npx ncu -u
npm install
Now, if we run npx ncu
again we get:
Now both package.json
and package.lock
were updated, so this makes it clearer what version of the packages we have without the need to look into the package.lock
file.
If you want to easily upgrade all your packages you can use the npm-check-updates
npm package with the commands shown above, otherwise, you can also use npm's built-in commands npm outdated
and npm update
.