Beginner LevelNode JS
How does Semantic Versioning (SemVer: MAJOR.MINOR.PATCH) work in npm dependencies?
❓ Interview Prompt: Explain SemVer spec (MAJOR.MINOR.PATCH), version prefix operators (`^`, `~`, `*`, exact), and lockfiles (`package-lock.json`).
Semantic Versioning specifies versioning rules in 'MAJOR.MINOR.PATCH' format (e.g. '2.4.1'):
•
MAJOR: Breaking API changes.
•
MINOR: Backward-compatible new features.
•
PATCH: Backward-compatible bug fixes.
Prefix Operators:
•
'^1.2.3': Updates MINOR and PATCH versions ('>=1.2.3 <2.0.0').
•
'~1.2.3': Updates PATCH versions only ('>=1.2.3 <1.3.0').
Code Implementation Example
json
{
"dependencies": {
"express": "^4.19.2",
"lodash": "~4.17.21",
"dotenv": "16.4.5"
}
}💡SemVer version range prefixes in package.json.
🎯 Interview Key Takeaway
Understand ^ vs ~ in package.json to prevent unintended breaking changes during npm update.
#SemVer#npm#package-lock.json#Beginner
Back to all Node JS Questions→