{"id":28515978,"url":"https://github.com/keygen-sh/example-private-npm-package","last_synced_at":"2025-07-05T17:31:01.280Z","repository":{"id":42546763,"uuid":"392699274","full_name":"keygen-sh/example-private-npm-package","owner":"keygen-sh","description":"An example of publishing a private Node package to a private npm registry hosted by Keygen","archived":false,"fork":false,"pushed_at":"2022-07-01T16:29:44.000Z","size":11,"stargazers_count":6,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-05T21:08:45.554Z","etag":null,"topics":["license-keys","node","npm-registry","private-npm","private-registry","software-licensing"],"latest_commit_sha":null,"homepage":"https://keygen.sh","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/keygen-sh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-04T13:29:27.000Z","updated_at":"2024-11-11T11:32:33.000Z","dependencies_parsed_at":"2022-09-09T18:54:07.008Z","dependency_job_id":null,"html_url":"https://github.com/keygen-sh/example-private-npm-package","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keygen-sh%2Fexample-private-npm-package","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keygen-sh%2Fexample-private-npm-package/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keygen-sh%2Fexample-private-npm-package/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keygen-sh%2Fexample-private-npm-package/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/keygen-sh","download_url":"https://codeload.github.com/keygen-sh/example-private-npm-package/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keygen-sh%2Fexample-private-npm-package/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":258813613,"owners_count":22762040,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["license-keys","node","npm-registry","private-npm","private-registry","software-licensing"],"created_at":"2025-06-09T03:31:32.188Z","updated_at":"2025-07-05T17:31:01.275Z","avatar_url":"https://github.com/keygen-sh.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Publishing a private npm module to Keygen\n\nSee blog post: https://keygen.sh/blog/how-to-license-and-distribute-commercial-node-modules/\n\n## Configuration\n\nFirst up, configure a couple environment variables. The values below are for our `demo`\naccount, which can be used in this example.\n\n```bash\n# Your Keygen product API token\nexport KEYGEN_PRODUCT_TOKEN=\"prod-xxx\"\n\n# Your Keygen account ID\nexport KEYGEN_ACCOUNT_ID=\"1fddcec8-8dd3-4d8d-9b16-215cac0f9b52\"\n\n# Your Keygen product ID\nexport KEYGEN_PRODUCT_ID=\"028e670a-9cc7-4dd2-af9e-78af5ccaf27f\"\n```\n\nThese environment variables will be used for creating new releases and uploading artifacts\nto the distribution API. All releases created will be for `KEYGEN_PRODUCT_ID`.\n\n## Publishing the module\n\nTo package and publish the module to Keygen, run the `publish` script:\n\n```bash\nnpm run publish\n```\n\nThis will perform [the following](https://github.com/keygen-sh/example-private-npm-package/blob/master/package.json),\nusing the `version` set in `package.json`:\n\n1. Package the module into a tarball using `npm pack`\n1. Upload the tarball artifact to Keygen\n1. Update the npm manifest artifact\n\n## Using the registry\n\nTo use Keygen as a private npm registry, we'll need to configure npm to retrieve modules\nunder the `@demo` scope from Keygen. You should change `demo` to whatever your account\nidentifier is.\n\n```bash\nnpm config set @demo:registry 'https://api.keygen.sh/v1/accounts/demo/artifacts/'\nnpm config set \"//api.keygen.sh/v1/accounts/demo/artifacts/:_authToken\" \"$KEYGEN_TOKEN\"\n```\n\nFor example, `KEYGEN_TOKEN` could be a license token for an end-user.\n\n#### Avoiding hardcoding tokens in `.npmrc`\n\nIf you'd rather not store your token in your global `.npmrc`, you can also tell npm to\npull the token from an env variable. For example, this would pull the token from a\n`KEYGEN_TOKEN` env var: (note single quotes)\n\n```bash\nnpm config set @demo:registry 'https://api.keygen.sh/v1/accounts/demo/artifacts/'\nnpm config set '//api.keygen.sh/v1/accounts/demo/artifacts/:_authToken=${KEYGEN_TOKEN}'\n```\n\n#### Project-specific `.npmrc` for CI/CD\n\nUse a project-specific `.npmrc` file with a variable for your token to securely authenticate\nyour CI/CD server. Project-specific `.npmrc` files can be safely checked into version control,\nsince the token is not hardcoded:\n\n```\n@demo:registry=https://api.keygen.sh/v1/accounts/demo/artifacts/\n//api.keygen.sh/v1/accounts/demo/artifacts/:_authToken=${KEYGEN_TOKEN}\n```\n\n## Installing the module\n\nNext, we can install the module, which npm should retrieve from Keygen:\n\n```\nnpm install -g @demo/hello-world\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeygen-sh%2Fexample-private-npm-package","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkeygen-sh%2Fexample-private-npm-package","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeygen-sh%2Fexample-private-npm-package/lists"}