DEV Community

Cover image for Lessons from publishing an NPM Package
Victor Nogueira
Victor Nogueira

Posted on

Lessons from publishing an NPM Package

The Quest

I always wanted to retribute the community for all those packages I use every day, but I couldn’t think of anything useful enough to be shared. For everything we can think of, there’s already at least one good package on NPM!

Fortunately, the opportunity for my contribution came in when I needed a package for dispatching strongly-typed events from one class to another, as in the Observer Pattern.

Well, in fact, there is a brunch of solutions for this already shared on NPM. If we close our eyes and click a random search result, we should be in good hands — there are excellent libs! But what I had in mind was very specific.

I was looking for a solution providing strongly-typed events that could be publicly listened but internally-only dispatched, fitting for both TypeScriptand JavaScript codebases.

The Adventure

Considering I had the whole spec in mind at that point, I decided to give it a try and implement it in Back Read, a game prototype that I had recently submitted for the Js13kGames competition.

Worked like a charm! I was euphoric! So I quickly extracted the code to a new repository and initialized an NPM package. Linked it to my game repository and… voilà! A new package was born!

But wait! Not so fast…

The Challenge

Having a pack of source files is not enough. A decent Readme, a well-defined package.json, minimal examples, and test coverage are the least we expect when looking for a lib on NPM. So, after reading some articles from experienced package maintainers, I did it all and more.

By the way, GitHub has nice Open Source Guides for helping with it.

The Achievement

Finally, it was in good shape to be shared on the NPM registry. So I logged in via command line and published it!

Alt Text

Typed Event Dispatcher was live! But now, how to let other devs know about it?

The Storytelling

This step is also important for the new package to have a good start. Developers spread the word about their libs through blog posts (Changelog.com, Dev.to, Medium, LinkedIn), social updates (Twitter, Facebook), chats (Slack, Discord), answers on Q&A portals (StackOverflow, Quora), forums, messengers and also in Meetups, Conferences.

Letting people have a glance at the project highlights using badges helps too. For this, Shields.io provides almost everything needed.

Alt Text

The Final Act

After that, we just need to keep the package updated, with repository issues resolved and the installs number will gradually increase. From now on, maintenance is the key.

Keep in mind that developers are more and more concerned about dependency bloat, so, besides quality and coverage, they value small-size and few-dependencies. Projects like BundlePhobia were born for it and should be used for self-checking.

I hope these thoughts can help those who are giving their first step into NPM publishing.

Have a great journey!

Discussion (0)