Fizer Khan Fizer Khan - 9 months ago 71
Javascript Question

Difference between tilde(~) and caret(^) in package.json

After I upgraded to latest stable

, I tried
npm install moment --save
. It saves the entry in the package.json with the
prefix. Previously, it was a

  1. Why are these changes made in npm?

  2. What is the difference between tilde(~) and caret(^)?

  3. What is the advantages over others?

Answer Source

In the simplest terms, the tilde matches the most recent minor version (the middle number). ~1.2.3 will match all 1.2.x versions but will miss 1.3.0.

The caret, on the other hand, is more relaxed. It will update you to the most recent major version (the first number). ^1.2.3 will match any 1.x.x release including 1.3.0, but will hold off on 2.0.0.

One can also use "1.2.x" or "2.x.x" as the version number.