DEV Community

Cover image for Tilde or Caret in package.json - Stop copying and start choosing
Mateus Malaquias
Mateus Malaquias

Posted on

5

Tilde or Caret in package.json - Stop copying and start choosing

TL;DR

Syntax Versions Dependency Impacts
tilde (~) 1.6.X ~1.6.7 only bug fix can be upgrade
caret(^) 1.X.X ^1.6.7 backwards compatible, deprecated and operational functionally, refactors, bug fix
  • Tilde (~): Use it for libraries where stability is crucial. Example: express framework.
  • Caret (^): Use it for libraries where you want to benefit from new features and bug fixes. Example: Jest, Prettier.

SEMVER

SemVer is a convention, not a law. What happens when each number changes:

  • Major: Something big has changed, and previous versions maybe will not work. 
  • Minor: New features or improvements, things should still work mostly the same.
  • Patch: Solves small issues without changing the structure.

Tilde (~)

  • Only allows patch updates.
  • Useful for getting the latest bug fixes and security patches while maintaining stability.
  • Use it for libraries where stability is crucial. Example: express framework.

Caret (^)

  • Allow both minor and patch updates.
  • Useful for staying up-to-date with new features and improvements, however, we have a risk of potentially breaking changes.
  • Use it for libraries where you want to benefit from new features and bug fixes. Example: Jest, Prettier.

How to update my dependencies?

npm outdated
Enter fullscreen mode Exit fullscreen mode

This command will scan your code for outdated packages compare with the latest version in the npm registry and no extra downloads needed because it is built into npm.

npm update
Enter fullscreen mode Exit fullscreen mode

This command will update the dependencies in package.json and package-lock.json using the "wanted" version.

Resources

Semantic Versioning 2.0.0
Node.js - Peer Dependencies
Node.js - An introduction to the npm package manager
Thanks to masahiro miyagi @masamasa3 for making this photo available on Unsplash 🎁

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❀ or a friendly comment on this post if you found it helpful!

Okay