Member-only story
How to Publish Your First npm Package
Everything You Need to Know to Create a Useful, Accessible npm Package

Once you’re up-and-running, publishing an npm package can be as easy as typing npm publish
into the terminal. But setting up your package for the first time, testing it locally and writing a useful README
can be tricky if you’re a first-timer.
Recently, I published my first public npm package. I solved a problem which applied to multiple of my personal projects, and so I thought — in case anyone else had the same issue — why not make the code publically-available as an npm package?
But, while there are some great resources out there about publishing an npm package, I ran into a couple of issues which none of them mentioned. That’s why I’m writing this article. In it, I’ll walk you through the whole process of publishing an npm package, from creating an account and version control to debugging your app and writing a great README
. Let’s go!
Install npm
Chances are, if you’re interested in contributing a package to npm, you’ll already have it installed. If not, it comes with Node.js, so head over to the Node.js site and install it.
Choose a package name
Before creating a new repository, it’s worth checking that your package name is available on npmjs.com: for an unscoped package, the name you choose has to be unique. If you use a scoped package, like @username/package
, this won’t be so important. Though you can — of course — choose the package name later, getting it right now will save you some time.
Initialise your project
Like every Node.js project, you’ll need a package.json
file. For private projects, you can get away with leaving most fields blank, but for a public npm package, you’ll want to provide as much useful information as possible.
A package.json
file must contain name
and version
fields, but in reality, you’ll likely want to cover the following fields: