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

white and brown animals near fence
Reading Time: < 1 minutes

Sometimes you need a dependency that is not published as a regular package at 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+"

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.

Related posts

Leave a Reply

%d bloggers like this: