Save Money with GitHub's Package Manager

Published: (February 25, 2026 at 03:44 PM EST)
3 min read
Source: Dev.to

Source: Dev.to

Prerequisites

Before you begin, ensure you have:

  • A GitHub repository containing your NPM package.
  • A minimal configuration of the package.json file.
  • A GitHub account with permissions to create repositories and manage packages.
  • Node.js and npm installed locally for development.

Configure the package.json File

Modify your package.json file to indicate that you’ll be using GitHub Package Manager. Update the name field to include your GitHub username as the scope:

{
  "name": "@your-username/your-package",
  "version": "1.0.0",
  "description": "A private package published on GitHub Package Manager",
  "repository": {
    "type": "git",
    "url": "https://github.com/your-username/your-repo.git"
  },
  "publishConfig": {
    "registry": "https://npm.pkg.github.com/@your-username"
  }
}

Be sure to replace your-username and your-repo with your actual GitHub username and repository name.

Generate an Access Token on GitHub

To publish your package, you’ll need a personal access token with the appropriate permissions.

  1. Go to GitHub Account Settings.
  2. Create a Personal Access Token (classic) with the following permissions:
    • write:packages
    • read:packages
    • repo (if the repository is private).

Save the token in a secure location, such as a password manager.

Configure GitHub Actions

Create a workflow to automate the process of building and publishing your package. Add the following YAML file to .github/workflows/publish.yml in your repository:

name: Build and Deploy

on:
  push:
    branches:
      - release

jobs:
  publish-gpr:
    runs-on: ubuntu-latest
    permissions:
      packages: write
      contents: read
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 20
          registry-url: https://npm.pkg.github.com/
          scope: '@your-username'
      - uses: pnpm/action-setup@v3
        with:
          version: 9.10.0
      - run: pnpm install
      - run: pnpm publish:build
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

This workflow triggers whenever you push changes to the release branch and automatically publishes your package to GitHub Package Manager.

Test the Workflow

Commit and push the .github/workflows/publish.yml file to the release branch. If everything is set up correctly:

  • GitHub Actions will trigger the workflow.
  • The package will be published to GitHub Package Manager.
  • You’ll find the package in the Packages tab of your repository.

Install the Published Package

To use the package in another project, add an .npmrc file to the project with the following content:

@your_username:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken=YOUR_TOKEN
engine-strict=true

Run the npm command to install the package:

npm install @your-username/your-package

Replace YOUR_TOKEN with the token created in the previous step.

Conclusion

Publishing private npm packages with GitHub Package Manager is a cost‑effective and streamlined alternative to traditional npm services. By leveraging GitHub Actions, you can fully automate the process, saving both time and resources.

This approach eliminates the need for paid npm private packages and integrates seamlessly into GitHub’s ecosystem, where your code, versioning, and packages are all managed in one place.

0 views
Back to Blog

Related posts

Read more »

Elevate Your Code Quality with Husky

Introduction In modern software development, maintaining code quality isn’t just a nice‑to‑have—it’s essential. As teams grow and codebases expand, ensuring co...

UV

Installation bash curl -LsSf https://astral.sh/uv/install.sh | sh Install a specific Python version bash uv python install 3.12 Create a virtual environment ba...