npm: host private packages on Github

January 02, 2021


You can host your silly private packages on GitHub.


I wrote some code in golang to evaluate web API development. I defined a couple of interfaces and implemented them. Testing was nice, and the language provided all the API I needed (base64, crypto, SQL etc.).

Then I looked at the Next.js framework and wondered JavaScript API couldn’t be bad with Typescript to manage all.

After all, I needed to build a client; one language to manage all would be more straightforward, too.

I will not go into details of the JS development but provide a summary. Porting the code to JavaScript with TypeScript was more painful as the test wasn’t built-in, and looking for packages took some time reading on how to install and use. I will add another post for an adventure creating packages with Typescript.

In the end, I built three packages to support my project.

I was DONE, but fetching from the local file system caused a problem when a relative path was used on a dependent package.
That is, it would have worked fine with a single package, but I had packages that depended on my other packages:


  • main
    • dep1
    • dep2

A project would fail to import dep1 with the relative path on the main. To fix that, I looked for better alternatives:

  • npm (public)
    • pro: free
    • con: must be public
  • npm (private)
    • pro: can share
    • cons: US$7
  • host on a shared folder (yay pi)
    • pro: npm works with URL path, yay.
    • cons: I have to copy files (more script) manually.
  • GitHub
    • pro: free, can share, can be private.
    • cons: requires git repository for the package

That’s it, publishing to GitHub for free! I started to put pet projects on GitHub, and I can put these repositories on GitHub.

How to setup (oh the pain)

  1. setup GitHub for a public access token and modify ~/.npmrc to include registry
    1. read Configuring npm for use with GitHub Packages - GitHub Docs
    2. read Creating a personal access token - GitHub Docs
  2. modify package.json to add `repository` and `publishConfig` as indicated in step 1
    1. ref package.json | npm Docs (

Why was it painful?

Entering GitHub password when registering the GitHub registry. It’s the Token.

Then it’s time to use the project:

`npm install @keenam/… —registry=\`

An error was reported as it required a package from public npm.

(More) How to set scope registry (more pain)

  1. modify ~/npm.rc
    1. read: scope | npm Docs (

Why was it painful?

The document on npmjs had an errata. It was missing the `=` sign.


Time to brag

Now it’s setup and I can brag and show scars.

© 2023 Kee Nam