Host and Publish NPM package on GitHub

In this post, we are going to explore the options to

  • host npm source code in GitHub
  • host npm package (both publicly and privately) in Github Packages
  • build, version and publish a npm package via GitHub Actions
  • Install GitHub hosted npm package in your project

We will use yarn as the package management tool (in most of the cases). You can replace it with npm and get the same result.

There is not too much to say, please refer to my example repo for an NPM example (derived from How to make a beautify, tiny npm package and publish it).

The NPM package hosted by GitHub is scoped with your GitHub account name: @scope-name/package-name. The package-name can be set via the name attribute in package.json.

It supports both public and private package (based on your GitHub repo is public or private).

The NPM publishing destination (rather than the default is controlled by publishConfig setting in package.json:

"publishConfig": {
"registry": ""

If you want to publish from your local machine, please follow the steps:

  1. You need a Personal access token from GitHub to be used as password on command line. It can be generated from Settings > Developer settings > Personal access tokens with correct permissions (at least read:packages, write:packages and repo, delete:packages optional).
  2. Run npm login --registry= and follow the prompt. (Note that yarn login doesn’t support specifying registry :( )
  3. Run yarn publish

(You only need to do steps 1 and 2 once and the authentication details will be stored in your ~/.npmrc).


  1. You cannot delete a public package yourself (similarly, npmjs only supports to delete a public package within 72 hours).
  2. The private repo is not available for free organization. Need at least GitHub Team level account.

Place this publish.yml under .github/workflows/publish.yml:

name: publish Node.js Package

- master

runs-on: ubuntu-latest
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
node-version: 12
- run: yarn install
- run: yarn test

needs: build
runs-on: ubuntu-latest
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
node-version: 12
scope: '@windix'
- run: yarn install
- run: git config --global "$" && git config --global "$GITHUB_ACTOR"
- run: yarn version --minor
- run: git push --tags && git push
- run: yarn publish


  1. Remember to replace scope with your own GitHub account name
  2. It triggers on new commits pushed onto master branch (the automatic push in the publish-gpr job won’t trigger!)
  3. Two jobs: build will run tests, if that passes, publish-gpr job will be triggered
  4. publish-gpr job will firstly bump the minor version number (e.g. 1.8.0 -> 1.9.0), tag git repo with the new version v1.9.0 and push back the new commit to GitHub (this has been done by yarn version). Then finally build and publish the new npm package to Github Packages (via yarn publish).
  5. Note that the authentication is done via the default GITHUB_TOKEN from the GitHub Actions environment.

A project level .npmrc is required, so package manager knows where to download the package:


If your NPM package is hosted privately, you also need to login first via npm login --registry= See previous section for details.

Now yarn add @windix/npm-tiny will install my latest version of npm-tiny to your project.


In case if you see a similar error:

error Integrity checked failed for "@windix/npm-tiny" (none of the specified algorithms are supported)

Use yarn add @windix/npm-tiny --upgrade-checksums instead to solve the issue.