Demo of using git+semver as npm dependencies.

This is part of a blog post.

This module isn't published on npm, so you have to use a git reference to install it, e.g.:

npm install --save git+ssh://

Then you can make sure you've installed it:

const demo = require('demo-npm-git-semver')

Of course, the problem here is that you don't know what version you installed, because you didn't specify a git commit hash or version or anything.

One solution is to use the commit hash:

npm install --save git+ssh://

But what we really want is to be able to use proper semver ranges (see also this handy semver calculator), that way if a patch is published we can get it automatically.

Conveniently, npm allows you to specify a semver range instead of a hash!

Instead of #1cbcec73 you use, for example, #semver:^1.0.3.

For example, if you wanted to say: use at least version 1.0.3 but use the latest 1.x.y:

npm install --save git+ssh://^1.0.3

In that demo repository, the highest 1.x version that I created is 1.1.3, so that's what will be installed:

const demo = require('demo-npm-git-semver')
console.log(demo()); // => 1.1.3