Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Upgrade Node Modules To Their Latest Versions With NPM 7

### Check What's Available For Update

Code

npm outdated

### For Minor And Patch Version Upgrades

Code

npx npm-check-updates --target minor --upgrade; npm install

This will update versions in your package.json and package-lock.json files for modules starting with `~` and `^` (i.e. the minor and patch versions)

### For Major Versions

Do a one time install of:

Code

npm install -g npm-check-updates

Then run these two commands:

Code

ncu -u
npm update

The `ncu -u` command updates the package.json so that when you run `npm update` it pulls the new major versions.

### Notes

- The official node documentation says to use `npm update` for minor versions and that "Since npm version 5.0.0, npm update will update the package.json with the updated version. Use npm update --no-save to not update package.json."

This is not the case in version 7. See this issue for reference.

- The `npm update` command does update `package-lock.json`. I don't know if it matters programmatically that the `package.json` file isn't updated, but it throws me off. That's what lead me to search for the above solution. (Actually, I'm not sure if it updated `package-lock.json`. Your milage may vary.)

- The docs page is currently the third search result for me. The first two are from 2015 and 2017, respectively and list even more outdated methods.

- Putting this in my grimoire but also linking to the docs in hopes that will raise it in the search results (and that it'll be corrected for v7).