How to publish an npm GitHub Package


This post goes over how to publish an npm GitHub Package.

Publish

Publish your npm package with GitHub Actions:

# .github/workflows/release.yml
# ...
jobs:
  publish:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write

    steps:
      - name: Checkout repository
        uses: actions/checkout@v6

      - name: Use Node.js
        uses: actions/setup-node@v6
        with:
          registry-url: 'https://npm.pkg.github.com'
          scope: '@your-org' # <- update with your org or username

      - name: Install dependencies
        run: npm ci --prefer-offline

      - name: Publish package
        run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

See example workflow.

Install

To install the npm GitHub Package, update .npmrc:

@your-org:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}

Replace your-org with your org or username.

Create auth token with scope read:packages and add it to your shell config (e.g., .zshrc):

export GITHUB_TOKEN=ghp_xxx

Or do with with GitHub CLI:

gh auth refresh -h github.com -s read:packages
echo 'export GITHUB_TOKEN=$(gh auth token)' >> ~/.zshrc

Now you can install the package!

See example repo.



Please support this site and join our Discord!