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

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.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s