Published my first NPM package - here's what I learned
Tags: webdev, javascript, productivity, npm
Published: 2020-11-16 06:47:34

Two weeks ago I've published my [Gatsby plugin as an NPM package](https://www.gatsbyjs.com/plugins/gatsby-omni-font-loader/). In short, I've noticed that Gatsby's font loading plugins were deprecated, outdated, and lacking some features, so I've developed a plugin that I wanted to actively maintain if it gains traction. You can read more about that story in my previous post.

{%link https://dev.to/prototyp/load-fonts-asynchronously-handle-fout-with-my-gatsby-plugin-19e %}

In those two weeks, my package received **almost 800 downloads**. I've learned some lessons about publishing your own NPM packages and maintaining open source projects that I would like to share with you all in this post.

{% github codeAdrian/gatsby-omni-font-loader %}

# Open-source mindset

Have you developed something useful, reusable and that is well-made? Why not publish it as an NPM package?

**Consider open-sourcing and publishing the NPM package that you wish you had available out of the box**. Because there is a good chance there are quite a few more devs out there who might find the code useful.

However, if you decide on publishing the package, you should also keep in mind that you should also maintain it. If the package gains traction with the community, you can expect a few issues to open up, feature requests, and pull requests.

For now, let's keep the focus on publishing the package.

# NPM best practices

I've outlined some NPM best practices in the article I wrote about a year ago.

{%link https://dev.to/adrianbdesigns/checklist-for-choosing-an-optimal-npm-package-4dpm %}

What does it mean for your NPM package?

* Make sure that dependency packages are kept up to date to avoid vulnerabilities
* Address any issues that have been reported
* Engage with people posting issues, feature requests, questions, etc.
* Keep the package and the code optimized
* Let the community know why your package stands above its competition

<figure>
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/z4rtbwkudxpdq72b4x44.PNG)
<figcaption>GitHub alerts you if your repo contains any vulnerabilities</figcaption>
</figure>

<figure>
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/fn9cv6e04mgp2pzk1edu.PNG)
<figcaption>It even creates automatic PRs for fixes</figcaption>
</figure>

# High-quality, informative docs

You need to provide informative docs so the community knows what your NPM package does, why they need it, and how do they use it.

Docs can be usually added with `README.md` in the repo and they usually feature:
* A short description of the package
* How to install it
* Simplest use-case
* Available options for configurations
* Examples and advance tips
* FAQ or troubleshooting (to avoid repeated questions or issues unrelated to your NPM package)

# Bug reports & contribution

As devs are downloading and using your npm package, it's unavoidable that they're either discover, have a feature request, send a pull request, or ask a question.

Maintaining a healthy user-base and engaging with the users is the best way to keep your NPM package going and used. No one likes to see an NPM package that has 10 or more issues open and no responses for weeks. That will discourage users from using your package.

# What to do if the package doesn't get any traction?

At the time of writing this article, there are exactly 1,445,808 packages on NPM. So it's no surprise if your package doesn't get any traction or is not widely used. You can bet there are at least a dozen alternatives for whatever package you decide to develop, so having some stand-out feature is important.

But what to do if the package doesn't get any traction? You can either:
* Spread the word - share it on social media, dev forums and channels, write articles, improve docs, ask colleagues to try it out...
* Deprecate it
* Transfer ownership to someone else who is willing to continue your work

If your package has dependencies, you don't want to leave it with vulnerabilities, so it's better to deprecate it if you decided not to continue maintaining it.

# Conclusion

Publishing an NPM package is not only a set-and-forget kind of thing. Your dependencies might be outdated which leads to security issues, and users might ask questions, report bugs, offer pull requests, etc.

If you are publishing the package, make sure that you are ready to engage with your users from time to time, and to make sure that the dependencies are up to date.

<hr />

These articles are fueled by coffee. So if you enjoy my work and found it useful, consider buying me a coffee! I would really appreciate it.

<a href="https://www.buymeacoffee.com/ubnZ8GgDJ" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-red.png" alt="Buy Me A Coffee" style="height: 51px !important;width: 217px !important;" ></a>

Thank you for taking the time to read this post. If you've found this useful, please give it a ❤️ or 🦄, share and comment.