EngineeringMar 03, 2026
Publishing a Private npm Package Using GitHub Actions (Complete Guide)
In this guide, Iβll show how to:
- Create a private npm package
- Publish it to GitHub Packages
- Automate publishing using GitHub Actions
- Install it securely in another project
π§± Step 1 β Create a Private Repository
- Go to GitHub
- Click New Repository
- Enter a name (example:
your-package-name) - Select Private
- Click Create Repository
π» Step 2 β Initialize Package Locally
Inside your project folder:
npm init -y
π Step 3 β Create index.js
const sayHello = function(name){
console.log("hello " + name + "!")
}
module.exports = {
sayHello
}
π· Step 4 β Update package.json
GitHub Packages requires scoped package names. Update your package.json:
{
"name": "@your-github-username/your-package-name",
"version": "1.0.0",
"main": "index.js",
"publishConfig": {
"registry": "https://npm.pkg.github.com"
}
}
[!WARNING] Replace
your-github-usernameandyour-package-name.
Example:"name": "@yunus-karatt/your-package-name"
π€ Step 5 β Push to GitHub
git init
git remote add origin https://github.com/your-username/your-package-name.git
git add .
git commit -m "initial commit"
git push -u origin master
βοΈ Step 6 β Add GitHub Action (Using Actions Tab)
- Go to your repository
- Click Actions
- Click Set up a workflow yourself

- Replace content with:
name: Publish Package
on:
push:
branches:
- master
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
registry-url: https://npm.pkg.github.com
scope: '@your-github-username'
- run: npm install
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- Click Commit changes.
Now every push to master will publish automatically.
οΏ½ Step 7 β Create a Personal Access Token (For Installing Package)
To install a private GitHub package, you must authenticate.
Create Token:
- Go to GitHub
- Click your profile photo β Settings
- Go to Developer settings
- Click Personal access tokens β Tokens (classic)
- Click Generate new token (classic)
- Select scopes:
- β
read:packages
- β
- Generate token and copy it (you wonβt see it again).
π¦ Step 8 β Install the Private Package
Inside the project where you want to use it:
Create .npmrc
@your-github-username:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=YOUR_PERSONAL_ACCESS_TOKEN
Replace
your-github-usernameandYOUR_PERSONAL_ACCESS_TOKEN.
Install
Using npm:
npm install @your-github-username/your-package-name
Using pnpm:
pnpm add @your-github-username/your-package-name
Using yarn:
yarn add @your-github-username/your-package-name
π§ͺ Step 9 β Use the Package
const { sayHello } = require("@your-github-username/your-package-name");
sayHello("Yunus");
Output:
hello Yunus!
π― What You Achieved
You built:
- A private scoped npm package
- Automated CI/CD publishing
- Secure installation using GitHub authentication
- Internal reusable library setup
This is exactly how companies manage shared UI components and internal tools.