With npm, `npm outdated` shows Current 2.1.0, Wanted 2.4.3, Latest 3.0.1 for a package; what does each mean, and what does `npm update` change?
answer
- the range npm wrote on install
- save-prefix defaults to a caret
- highest version inside the range
- the latest dist-tag
- npm update --save rewrites the range
basics
~10 sCurrent is the installed version, Wanted the highest version satisfying the package.json range, Latest the version tagged latest. npm update installs within the range (2.4.3) and leaves package.json alone unless run with --save.
solid answer
~40 sWhen you ran `npm install date-adapter`, npm saved `"^2.1.0"`: the `save-prefix` config defaults to `^` (`--save-exact` writes `2.1.0` instead). `npm outdated` then compares three versions: **Current** is what sits in `node_modules`, **Wanted** is the highest published version that satisfies the range in `package.json`, and **Latest** is whatever the `latest` dist-tag points to, which is usually but not necessarily the highest version. `npm update date-adapter` moves the install to the newest version the range allows, here 2.4.3, unless another package's narrower requirement on the same package holds it lower. By default `npm update` does not rewrite the range in `package.json`; `npm update --save` does. Reaching 3.0.1 crosses the range, so it takes an explicit `npm install date-adapter@latest`.
code
bash · 13 lines# package.json has "date-adapter": "^2.1.0" (written by npm install, save-prefix ^)
$ npm outdated
Package Current Wanted Latest Location Depended by
date-adapter 2.1.0 2.4.3 3.0.1 node_modules/date-adapter dispatch-dashboard
# installs 2.4.3; package.json still reads ^2.1.0
$ npm update date-adapter
# installs within the range and also rewrites the entry in package.json
$ npm update date-adapter --save
# crosses the major on purpose and rewrites the declaration
$ npm install date-adapter@latestgo deeper
Recall that npm install saved a caret range and what Current, Wanted and Latest each stand for.
Explain how save-prefix and --save-exact shape the range and why npm update stops at Wanted without editing package.json.
Use red versus yellow rows to plan upgrades, explain an update that lands below Wanted, and wire npm outdated's exit code into CI sensibly.
Decide a team default, exact saves or ^ ranges plus a lockfile and scheduled npm outdated reviews, against how much upgrade churn the team can absorb.
## The range npm writes when you add a package Every `npm outdated` row starts from a range that `npm install` wrote earlier. Adding a package by name installs the version behind its `latest` tag and saves a range built from two configs: - **`save-prefix`**, default `^`. For version 2.1.0 npm writes `"date-adapter": "^2.1.0"`. After `npm config set save-prefix='~'` it would write `~2.1.0`. - **`save-exact`**, default `false`. With `--save-exact` (`-E`), or `save-exact=true` in an `.npmrc`, npm writes the bare version `2.1.0`, and `save-prefix` is ignored. What each operator allows is a semver question with its own material; what matters here is that the saved range is the boundary every later command respects. A committed project `.npmrc` with `save-exact=true` makes every teammate's additions exact without anyone remembering the flag. ## Reading `npm outdated` `npm outdated` asks the registry about your installed packages. By default it lists the direct dependencies of the root project (and of configured workspaces); `--all` adds transitive ones. | Column | Meaning | Where it comes from | |---|---|---| | Current | the version installed now | `node_modules` | | Wanted | the highest version that satisfies the `package.json` range | registry versions filtered by your range | | Latest | the version tagged `latest` | the package's `latest` dist-tag | | Location | where the package sits in the tree | the installed tree | | Depended by | which package declares it | the edge that pulled it in | Three reading rules: 1. **Red** rows have a newer version inside your range, so an update stays within what your own declaration allows. 2. **Yellow** rows have a newer version only *above* your range, usually a new major, so read the changelog first. 3. **Latest is not always the maximum.** Maintainers move `latest` themselves; npm's own docs show a row where Wanted is higher than Latest because a newer version was published under another tag. `npm outdated` exits with code 1 whenever it lists anything, so a CI step that runs it fails when a package is outdated; `--long` adds the dependency type and homepage. ## What `npm update` does with the range `npm update` installs, for each listed package (or all of them), the newest version that the semver constraints allow, and installs anything missing. For the row above, `npm update date-adapter` installs 2.4.3. - It **respects every constraint on the package**, not only yours. If another dependency also requires `date-adapter` with a narrower range, npm prefers a single copy that satisfies both, so the result can stay below Wanted. - It **does not cross your range**. 3.0.1 is outside `^2.1.0`, so `npm update` never installs it. - It **does not rewrite `package.json` by default**: the `save` config defaults to `true` everywhere except `npm update`, where it defaults to `false`. Run `npm update --save` (or set `save=true` for it) if you want the manifest's lower bound to follow. - With an exact entry such as `2.1.0`, Wanted equals Current and `npm update` has nothing to move; exact pins are upgraded only by an explicit install. ## Crossing a major on purpose To adopt 3.0.1 you change the declaration itself, for example with `npm install date-adapter@latest` or a specific version or range. npm installs it and rewrites the entry in `package.json`. That is a deliberate change of contract, which is why `npm update` refuses to make it for you. A practical routine on a dashboard team: 1. Run `npm outdated` and sort the rows into red (inside the range) and yellow (outside it). 2. Apply the red rows with `npm update`, run the tests, and commit the result, adding `--save` if the team wants the manifest to record the new floor. 3. Take each yellow row as its own change with `npm install <pkg>@<new major>`, read its release notes, and review it like code. ## Interview traps - Treating Latest as "the highest version that exists" misses that it is just a movable tag. - Expecting `npm update` to jump majors confuses it with installing a new version explicitly. - Expecting `npm update` to edit `package.json` by default forgets that its `save` default is the exception. - Assuming `npm outdated` lists every package in the tree: by default it shows direct dependencies of the root and its workspaces, and `--all` widens it. - Forgetting that the saved prefix is configuration: a project `.npmrc` with `save-prefix=~` or `save-exact=true` changes what every later `npm install <pkg>` writes, and therefore how far Wanted can ever move.
- `npm outdated` shows Wanted 2.4.3, but after `npm update` the package stops at 2.3.9. Why?Wanted is computed from your own range only. `npm update` also honours other packages that depend on the same one; if a dependency asks for `~2.3.0`, npm prefers a single copy satisfying both ranges, so it settles on the highest version inside both. Raising that dependency, or installing your version explicitly, changes the result.
- How do you make every package a teammate adds land as an exact version?Set `save-exact=true` in the project's `.npmrc` and commit it. `npm install <pkg>` then writes the bare version instead of the `save-prefix` range, for everyone who works in the repository, without anyone having to pass `--save-exact`.
- Latest is always the highest version ever published
- npm update moves a package to the next major when one exists
- npm update rewrites package.json ranges by default
- npm install saves the bare version unless you pass a prefix
- Wanted is the version the lockfile recorded
- npm outdated exits 0 even when it lists packages