Jonathan.Brink Jonathan.Brink - 1 year ago 66
Node.js Question

Use latest major version

In my JavaScript applications I may be declaring a few dozen dependencies in my


It would take a while to go through each one of those dependencies and see which version they are on.

I just want to say: use the latest major version, but not the bleeding edge.

As an example, with a tool like Git I don't usually care about taking changes at the patch-level but if a new major release comes out I will want it.

Is there a similar concept when specifying the version of a npm module?

Answer Source

NPM packages (theoretically) use SemVer.

In SemVer, packages get a version number of X.Y.Z.

Z indicates bug fixes. Y indicates new features without changing existing ones. X indicates a major version that breaks backwards-compatibility.

Doing npm install --save <package> will result in a version string in your package.json like ^2.3.9, which means "anything in the 2.* range greater than or equal to 2.3.9". This'll mean you get bug fixes and non-breaking new features, but you won't unexpectedly be updated to a version 3.0.0 that breaks your application.

Note: I say "theoretically" because not everyone sticks to SemVer's ideal. You may find a 2.3.9 -> 2.3.10 upgrade that breaks stuff at times. Tests are handy here.