Express.js Mastery / Introduction To Node.js And NPM

Package Versioning and Updating

🏷️ Understanding Package Versions

Node.js packages generally follow Semantic Versioning (SemVer):

πŸ”’ Common Version Ranges

"express": "5.1.0"
  • Exact: Only 5.1.0

"express": "^5.1.0"
  • Caret (^): Allows minor and patch updates within major version 5

"express": "~5.1.0"
  • Tilde (~): Allows patch updates within 5.1


πŸ”’ package.json vs package-lock.json

package.json β€” what's allowed

"express": "^5.1.0"

Declares the acceptable range of versions for each dependency β€” a rule, not a specific version. Anyone installing your project could end up with a different exact version, as long as it satisfies the range.

package-lock.json β€” what's actually installed
Records the exact version of every package that got installed β€” including all the nested (transitive) dependencies those packages themselves depend on. This file is what makes installs reproducible: run npm install on any machine, and you get the identical dependency tree every time.

File

Think of it as

package.json

The range you're willing to accept

package-lock.json

The exact snapshot that was installed


⬇️ Installing and Updating Packages

πŸ“₯ Install a Package

npm install express

🎯 Install a Specific Version

npm install express@5.1.0

πŸš€ Install the Latest Version

npm install express@latest

πŸ› οΈ Install a Development Dependency

npm install -D eslint

πŸ” Check Outdated Packages

npm outdated

Example:

Package   Current   Wanted   Latest
express   5.1.0     5.1.3    6.0.0
  • Current β†’ Installed version

  • Wanted β†’ Latest version allowed by package.json

  • Latest β†’ Latest published version

πŸ”„ Update Packages

npm update

Updates packages within their allowed version ranges.

For a major upgrade:

npm install express@latest