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


Posted on Aug 30, 2020


featured image

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.


nodejs javascript npm dev
Search
Side Widget
You can put anything you want inside of these side widgets. They are easy to use, and feature the new Bootstrap 4 card containers!