How to Publish NPM Package to Github

2023/02/011 min read
bookmark this
Responsive image

Table of Contents

  1. Introduction
  2. Modify Package.json
  3. Publish
  4. Conclusion

Introduction

This guide walks you through how to publish an NPM package to GitHub Packages. You will need to modify your package.json and then use the npm publish command.

Modify Package.json

name

  "name": "@keke78ui9/node-reading"

publishConfig

"publishConfig": {
    "registry": "https://npm.pkg.github.com"
},

version

"version": "1.0.6",

Publish

Npm Login

npm login --scope=@NAMESPACE --auth-type=legacy --registry=https://npm.pkg.github.com
> UserName: username
> Password: token

Publish npm package

npm publish --access public

Conclusion

That's it! By updating the name, publishConfig, and version fields in your package.json, and then logging in and running npm publish, your package will be published to GitHub Packages.