Skip to content
Tutorials Center
My learning

Topics

Lesson 13 of 36 ยท Installing and Versions

Updating and Outdated Packages

Learn how to find outdated dependencies with npm outdated, update within ranges, upgrade across majors, use npm-check-updates, yarn upgrade-interactive and pnpm update --latest, and avoid breakage.

Software is never finished, and neither are its dependencies. New versions bring security fixes, bug fixes and features, but each update also risks breaking something. A good update routine is small, frequent and tested. This lesson shows how to see what is outdated, the difference between updating inside a range and upgrading to a new major version, and how to keep risk low.

Seeing what is outdated

Terminal
npm outdated
yarn outdated         # Yarn Classic; Berry: yarn upgrade-interactive
pnpm outdated

npm outdated prints a table with four columns that matter:

Column Meaning
Current the version installed now
Wanted the newest version that satisfies the range in package.json
Latest the newest version published (the latest tag)
Location where it is installed

If Wanted equals Current but Latest is higher, the new version lies outside your range, typically a new major release. If Wanted is higher than Current, a plain update will fix it.

Node.js Compute Current, Wanted and Latest

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Updating inside your ranges

Terminal
npm update            # everything, within ranges
npm update lodash     # one package
yarn upgrade          # Classic; Berry: yarn up
pnpm update

npm update installs the Wanted versions and rewrites the lockfile. It changes package.json only if you also pass --save semantics (modern npm updates the range's minimum to the installed version). Because your ranges already limit you to compatible changes, this is usually safe: run your tests afterwards, then commit package.json and the lockfile together.

Upgrading across a major version

To move past the range, you must opt in explicitly:

Terminal
npm install express@latest      # or: npm install express@5
yarn add express@latest
pnpm update express --latest

A major bump means breaking changes. Read the package's changelog or migration guide first, upgrade one major at a time, and fix errors before the next update. Do not mix a large upgrade with other changes in the same commit, so you can find the culprit when something breaks.

Tools make batch upgrades easier:

  • npm-check-updates (npx npm-check-updates -u) rewrites ranges in package.json to the newest versions, then you run npm install.
  • yarn upgrade-interactive (Classic and Berry) and pnpm update -i --latest show a checklist you tick through.
  • Bots such as Renovate and Dependabot open pull requests per update, so CI runs before you merge.

Why small, frequent updates win

Node.js Risk grows with the size of the jump

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The numbers are made up, but the shape is real: a year of skipped releases means a big, risky upgrade, while a weekly update means a tiny diff you can review in minutes.

Security updates

npm audit lists known vulnerabilities in your tree, and npm audit fix applies fixes that stay inside your ranges. Treat npm audit fix --force with care: it may install breaking major versions. Details come in the Lockfiles and Security chapter.

A safe update routine

  1. Make sure tests pass and the working tree is clean (git status).
  2. Run npm outdated and pick a batch: patch and minor updates first.
  3. npm update, then run tests and the app.
  4. Commit package.json and the lockfile together with a clear message.
  5. Handle majors one package at a time, reading release notes.
  6. If something breaks and you cannot fix it quickly, revert the commit; the lockfile makes that exact.

Showing the version a range would pick

Node.js Which update command do I need?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Pinned and ranged versions also appear in your lockfile. How that file works is explained in lockfiles (covered in the Lockfiles and Security chapter), and a quick recap of ranges is in Version Ranges.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In npm outdated, what does Wanted mean?

    Wanted is the highest version allowed by your range.
  2. 2. Wanted equals Current but Latest is higher. What does that tell you?

    The range blocks the newer release, so you must upgrade deliberately.
  3. 3. What should you read before a major upgrade?

    Major versions may contain breaking changes.
  4. 4. What does npm update do?

    It moves packages up to the Wanted versions.

Summary

  • npm outdated shows Current, Wanted and Latest.
  • npm update stays inside your ranges; crossing a major needs an explicit install of the new version.
  • Update in small batches, run tests, commit manifest and lockfile together.
  • Tools like npm-check-updates, Renovate and Dependabot automate the routine.
  • Read changelogs before major upgrades; use audit for security fixes.

Next: Global Installs and npx