Semver in package.json: ^, ~, or exact version

Do you actually know what version you're installing? Most developers write ^, ~, or just a number in package.json without thinking twice — but they behave very differently. Here's a quick breakdown: ^ (Caret) — ^4.19.1 Allows minor + patch updates. Stays on major version 4. Range: ≥4.19.1 <5.0.0 ~ (Tilde) — ~4.18.7 Allows patch updates only. Minor version locked to 18. Range: ≥4.18.7 <4.19.0 Exact — 4.12.4 Pins to this exact version. No updates ever. Range: = 4.12.4 only ✅ Use ^ when you trust the library follows semver and want latest features. 🔒 Use ~ when you want stability but still need bug fixes. 📌 Use exact version when you need 100% reproducibility — CI/CD pipelines, production lockdowns. Pro tip: Always commit your package-lock.json or yarn.lock. The ranges in package.json are intentions — the lock file is what actually gets installed. Which one do you use most? Drop a comment 👇 #javascript #nodejs #npm #webdevelopment #softwareengineering #100daysofcode #devtips

To view or add a comment, sign in

Explore content categories