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 🎁

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay