Automate publishing your Node.js package to GitHub Packages using a CI workflow. You can adapt these steps for npm or other registries. First, review the official GitHub documentation on publishing Node.js packages in a workflow:Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.


Prerequisites
- Unique package scope
Inpackage.json, define a scoped name and version:
The
repository field is optional but helps link the package back to this GitHub repo.-
.npmrc setup
Theactions/setup-nodeaction auto-generates a local.npmrcon the runner, pointing to your GitHub registry and injectingNODE_AUTH_TOKEN. -
Workflow permissions
Ensure yourGITHUB_TOKENhas:Permission Access Level Purpose contents read Checkout repository packages write Publish to registry
Configure the GitHub Actions Workflow
Create.github/workflows/publish-package.yaml:
- Trigger: on
release.published. - Setup: installs Node.js, configures
.npmrcfornpm.pkg.github.comwith your scope. - Publish: uses
GITHUB_TOKENfor authentication.
Sample Repository Structure
Before you add the workflow, your repository might look like this:
package.json:
Publishing a Release
- Go to Releases → Draft a new release.
- Set the tag (e.g.,
v6.7.6), title, and description. - Click Publish release.

Workflow in Action
After you publish the release, the workflow is queued:

- Node.js setup
- Dependencies installation
.npmrccreation- Package publication

View and Install Your Package
Your package appears under Your GitHub Profile → Packages:
package.json dependencies: