How to use a GitHub repository as a dependency in Node.js

How to use a GitHub repository as a dependency in Node.js
Reading Time: < 1 minute

Sometimes you need a dependency that is not published as a regular package at npmjs.com. Probably is the case of a private package.

Node.js allows remote dependencies such as GitHub private repository, so let explain how to do that.

We will need a GitHub personal token. In your GitHub account go to

Settings–>Developer settings–>Personal access tokens.

After that, generate a new token with the permissions you need (probably read-only).

Your package.json will look like this:

"dependencies": {
  "module-name": "git+https://TOKEN_FROM_GITHUB:x-oauth-basic@github.com/My-company/my-repo.git"
}

If you want to point to a specific branch add #your-branch at the end of the url so, /My-company/my-repo.git#your-branch

Remember to run npm install after you save the package.json file.


About the author

Andrés Canavesi
Andrés Canavesi

Software Engineer with 15+ experience in software development, specialized in Salesforce, Java and Node.js.


Join 22 other subscribers

Leave a Reply

Discover more from javaniceday.com

Subscribe now to keep reading and get access to the full archive.

Continue reading