This is something that came across in our project that we think it's pretty useful. And despite now having the ability to host your own
npm packages on the Github package Registry; some people might find this helpful, even if the repo itself didn't mean to be an
npm isntallable module.
> npm install <githubname>/<githubrepo>
That's the basic syntax, although you might want to use the explicit version:
> npm install github:<githubname>/<githubrepo>
BTW, this works with private repos too! Also does Github Package Registry ones. But it is possible that you will be prompted with the Git Credentials Manager to put your user/pass in order to continue.
The good part, is that you can also specify versions (using semver), as in every
npm package. And update them afterwards accordingly.
> npm i github:<githubname>/<githubrepo>[#semver:<semver>] # Example: > npm i github:lodash/lodash#semver:4.17.15
And another cool thing about this github option is that
npm allows you to specify specific commits too!
> npm i github:lodash/lodash#ddfd9b1
It will use the main branch in the respository, by default; usually
"Installing from a gist?" You might say. Sometimes it's useful to have little snippets that aren't as important as to make an npm package out of them in Github Gists.
Take a look this example: https://gist.github.com/gangsthub/0bce1161cfd2aa91ae7cad9abb42c342
If they have a
package.json properly configured, you can install them.
You can then do:
> npm i gist:0bce1161cfd2aa91ae7cad9abb42c342
Note, the hash is the id of the gist, also used in the URL.
That's it! Also it's my first published post on Dev.to! Make sure to: