
package.json
file in yournode project contain (among others) links to the packages that your projects needs to run.
To add new package dependency, you can runnpm add
command:
npm add chalk
And after that respective package will be added to thedependencies
section of yourpackage.json
:
{"name":"sandbox","main":"index.js","dependencies":{"chalk":"^4.1.2"}}
But what if instead of apublished npm package I want to use a branch that is living on GitHub? Luckilypackage.json definition allows GitHub URLs. The syntax is one of:
github:[user]/[project]github:[user]/[project]#[commit-sha]github:[user]/[project]#[branch]github:[user]/[project]#[tag]
Thegithub:
part is optional, but gives some context to your future self.
Whereuser
andproject
you can extract from the GitHub URLs of respective repositories:https://github.com/[user]/[project]/
So for example to install commit95d74cbe8d3df3674dec1445a4608d3288d8b73c
of the package/projectchalk
(which happens to have GitHubuser of the same name) I would have to specify:
{"name":"sandbox","main":"index.js","dependencies":{"chalk":"github:chalk/chalk#95d74cbe8d3df3674dec1445a4608d3288d8b73c"}}
Semver
There is one more curious format that can be used in GitHub URLs and that issemver. The syntax is:
github:[user]/[project]#semver:[semver]"
So for example to installchalk
withsemver^2.4.1
we should put following into ourpackage.json
:
{"name":"sandbox","main":"index.js","dependencies":{"chalk":"github:chalk/chalk#semver:^2.4.1"}}
Top comments(2)

- Email
- LocationGermany
- Pronounsshe/her
- WorkLibrary Developer for @Discord
- Joined

- Email
- LocationInterlaken, Switzerland
- EducationUniversity of West Bohemia
- Pronounshe/him
- WorkSandcastle Architect
- Joined
Ha! Actually took me a while to spot thegithug
. Thanks for pointing that out!
For further actions, you may consider blocking this person and/orreporting abuse