How to Choose Your NPM Packages

In this latest blog from the developers on our Product Traction team, they offer a comprehensive guide to choosing your NPM packages.

Selecting the right NPM packages is a crucial part of any JavaScript development project. With over a million packages available, it's easy to get overwhelmed by the sheer volume of choices. However, making the wrong choice can lead to security vulnerabilities, maintenance headaches, and project delays. In this post, we'll explore the criteria that should guide your decision-making process when selecting NPM packages, along with some real-world examples to illustrate these points.

1. Popularity Metrics: Stars, Downloads, and Beyond

When browsing for an NPM package, it's tempting to pick the one with the most stars or weekly downloads. These popularity metrics can give you a sense of how widely adopted a package is. For example, packages like lodash or express boast millions of weekly downloads, which speaks volumes about their reliability and community support.

However, popularity alone shouldn't be your only criterion. A high download count could be due to historical usage rather than current quality. It's also worth noting that popular packages tend to have more Stack Overflow questions answered and more detailed blog posts written about them, making it easier to troubleshoot issues.

Anecdotal Example:

I once picked a package based purely on its star count and popularity. It worked well initially, but as my project scaled, I started noticing performance issues. Upon further investigation, I found that the package had not been updated in over two years, and there were numerous unresolved issues on its GitHub page. This experience taught me the importance of looking beyond the stars.

2. The Hidden Risks: Spam Packages

Believe it or not, about 80% of new NPM packages are spam. This alarming statistic highlights the importance of due diligence when selecting packages. Spam packages often contain malicious code or are simply low-quality forks of legitimate ones. They can even be part of schemes to exploit open-source funding platforms, where creators might receive grants for developing "new" software, regardless of its quality or usefulness.

Anecdotal Example:

A colleague of mine once mistakenly included a spam package in a project. It looked legitimate at first glance, but after running some security checks, we discovered that it was mining cryptocurrency in the background. We had to quickly remove it and replace it with a more reputable package, which delayed the project by several days.

3. Minimizing Dependencies for Stability

The fewer dependencies a package has, the better. Each dependency introduces a potential point of failure, and the more dependencies a package relies on, the more brittle it can become. If you can find a package that has zero dependencies, it's likely to be more stable in the long run.

Anecdotal Example:

I once worked on a project where we used a package with over 20 dependencies. Everything was fine until one of those dependencies introduced a breaking change in a minor version update. This caused a cascade of issues that took days to resolve. Since then, I've made it a point to favor packages with minimal or no dependencies.

4. Who Maintains the Package?

Knowing who maintains the package is crucial. Many open-source maintainers work on these projects in their spare time, often without financial compensation. There have been instances where maintainers, frustrated by the lack of support from big companies using their software for free, have abandoned their projects or introduced breaking changes intentionally.

Anecdotal Example:

One famous case involved the developer of colors.js and faker.js, who sabotaged his own libraries in response to what he saw as exploitation by large companies. This incident affected thousands of projects and highlighted the importance of understanding the motivations and sustainability of the package maintainers.

5. Consider the Scale of Your Project

The scale of your project should dictate how much scrutiny you apply when choosing a package. For small, one-off tasks, you might be more willing to experiment with less established packages. However, for large-scale applications, it's essential to choose well-established, thoroughly vetted packages.

Anecdotal Example:

In a small side project, I needed a library to handle date formatting. I picked a lightweight, relatively unknown package because it was easy to use and did the job. But for a large enterprise application, I stuck with moment.js, even though it's heavier, because of its reliability and extensive documentation.

6. The Role of Documentation

Good documentation is often the difference between a package you can integrate in minutes and one that takes days. A well-maintained GitHub README, with clear instructions and examples, is a strong indicator that the package is well-maintained and user-friendly.

Anecdotal Example:

I once tried to use a package that seemed perfect for my needs, but the documentation was sparse and outdated. After hours of trial and error, I gave up and switched to a different package with better documentation. It turned out to be much easier to integrate and saved me a lot of time.

7. Reviewing the License

Licenses can sometimes be overlooked, but they are critically important. Some licenses restrict how a package can be used, especially in commercial projects. Before integrating a package, make sure you understand its license to avoid legal issues down the road.

Anecdotal Example:

A few years ago, a project I was involved in ran into licensing issues when we tried to commercialize the software. We had used a package with a GPL license, which required us to open-source our own code. This was not an option, and we had to rewrite large portions of the software using different packages with more permissive licenses.

Choosing the right NPM packages requires more than just glancing at popularity metrics. It's about understanding the broader ecosystem, assessing the stability and maintenance of the package, and considering the scale of your project. By taking the time to evaluate these factors, you can avoid the pitfalls of spam packages, outdated dependencies, and license issues. Remember, the right package can save you time and effort, while the wrong one can lead to delays, security vulnerabilities, and frustration. Take the time to choose wisely.


The Thin Air Labs Product Traction team provides strategic product, design and development services for companies of all sizes, with a specific focus on team extensions where they seamlessly integrate into an existing team. Whether they are deployed as a team extension or as an independent unit, they always work with a Founder-First Mindset to ensure their clients receive the support they need.

To learn more about our Product Traction service, go here.

Build what's next with us