← Back to Node.js Course | Chapter 3: npm & Packages | Lesson 5 of 7

Semantic Versioning क्या है

2.4.1 जैसे Version numbers एक pattern follow करते हैं जो बताता है एक upgrade कितना risky है।

In this page:

  1. Semantic Versioning
Syntax
javascript
"package_name": "MAJOR.MINOR.PATCH"
"package_name": "^MAJOR.MINOR.PATCH"
"package_name": "~MAJOR.MINOR.PATCH"

Semantic Versioning

Semver MAJOR.MINOR.PATCH इस्तेमाल करता है। Patch bugs fix करता है, minor backward-compatible features add करता है, और major चीज़ें तोड़ सकता है। package.json में, एक caret minor और patch updates allow करता है, एक tilde सिर्फ patch updates allow करता है, और एक exact version इसे pin करता है।

Note: ^1.2.3 1.2.3 से लेकर (लेकिन शामिल न करते हुए) 2.0.0 तक कुछ भी allow करता है।

उदाहरण: Semantic versioning

javascript
function allowsCaret(range, version) {
  const [rM, rm, rp] = range.replace("^", "").split(".").map(Number);
  const [vM, vm, vp] = version.split(".").map(Number);
  return vM === rM && (vm > rm || (vm === rm && vp >= rp));
}
console.log("^1.2.3 allows 1.9.0:", allowsCaret("^1.2.3", "1.9.0"));
console.log("^1.2.3 allows 2.0.0:", allowsCaret("^1.2.3", "2.0.0"));
console.log("^1.2.3 allows 1.2.2:", allowsCaret("^1.2.3", "1.2.2"));

// Output:
// ^1.2.3 allows 1.9.0: true
// ^1.2.3 allows 2.0.0: false
// ^1.2.3 allows 1.2.2: false

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह मान लेना कि कोई भी upgrade safe है
  2. caret और tilde को confuse करना
  3. lock file commit न करना
चैप्टर सारांश
  • MAJOR.MINOR.PATCH format इस्तेमाल होता है
  • Caret minor और patch allow करता है
  • Tilde सिर्फ patch allow करता है
  • Lock files exact versions pin करती हैं
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.