Your First Github npm Package in 5 Minutes
In this quick take, we're going to get you up and running with your first npm package on GitHub.
It expects you to be relatively familiar with npm and GitHub.
Create an Access Token on GitHub
On GitHub (once logged in), click on the top-right dropdown in the toolbar and head to
Settings > Developer > Personal Access Tokens and create a new access token with:
- Repo access
- Read package access
- Write package access
- Delete package access (optional)
Copy the token and add it to
~/.npmrc with the value
Now log into the registry:
Publishing the first package
Head to the hello-world-npm repo and fork it into your own GitHub account.
Once forked, let's clone it into your local. That should be
git clone https://github.com/your-username/hello-world-npm.git.
Change into that directory and open it up into an editor. We want to make some changes to
Save and let's commit this and push back up.
Finally, let's publish the package!
Bingo! We should be ready to roll.
Installing the package
Let's start a new Nodejs project.
We need to add
@your-username:registry=https://npm.pkg.github.com to the
.npmrc file to tell it to look for your packages.
nnpm i @your-username/hello-world-npm.
This should successfully install. Once happy, let's test it out! Add the following inside
We are now all set to try it out! Run
node index.js and we'll get our glorious response!
The important part from all of this is to ensure that you have correctly configured
package.json for your NPM packages.
Resources and Further Reading
Image credit: Morning Brew
1,200+ PEOPLE ALREADY JOINED ❤️️
Get fresh posts + news direct to your inbox.
No spam. We only send you relevant content.