Build a TypeScript Project From Scratch Tutorial (19 exercises)

Publish Library to npm

In this lesson, you will publish your streak-counter on npm as a package.


The following resources provide more information for this lesson:


[0:00] [0: 00] After you create an npm account, go into Access Tokens and create a new token. For the token, select Automation, and then click Generate Token.
[0:08] [0: 08] Once you have your token, go to your GitHub repo settings, and go to Secrets, Actions. Create a New repository secret, and we'll call this NPM_TOKEN. Paste in your secret. We'll create a new file called .github/workflows/publish.yaml. Paste this in.

[0:28] [0: 28] The main thing I want to point out is we're adding a working directory to this job. We're adding the working directory because that's where we're working from. That way, we don't have to add it to every run step here.

[0:39] [0: 39] We're using an action to publish that corresponds to our environment secret or pointing to our package.json. We're setting access to public since it's a scoped package. Commit that, push it up.

[0:51] [0: 51] Now to GitHub, you should see a beautiful green checkmark, meaning everything was successful. Finally, if you head to npm, you'll see that it was successfully published.