Stop adding npm dependencies (thoughtlessly) !  
Tags: javascript, node
Published: 2019-11-07 12:43:52

Have you ever checked what happens when you run npm install xyz --save ?  Or looked at the real *weight* of used packages? Or maybe examined the dependencies of your dependencies?

Let's assume that we have a few packages which deliver the same or similar value. There are many factors which we can consider when we have to make a choice 
between them.  Personally, for long time I used some kind of popularity contest, what my team is using, downloads count on npmjs.com, stars on Github... 
I also used different factors like the quality of documentation, the state of the project, is it still maintained or not, etc., ect. But I've never thought about the *weight* of the dependencies.

If you look at [this answer](https://stackoverflow.com/questions/16389851/how-do-i-choose-a-node-module) on stackoverflow.com or [this one](https://www.quora.com/How-does-one-choose-npm-modules-to-use-for-a-project) on quora.com or check how the [npms.io](https://npms.io/) is [measure the quality](https://npms.io/about) of the package, you can notice that *weight* is not mentioned there. 

You probably saw that image:
![Node modules heaviest objects in the universe](https://thepracticaldev.s3.amazonaws.com/i/vu4h6o8blxajz1dqj48u.png)
*Source: [devrant.com/rants/760537...](https://devrant.com/rants/760537/heaviest-objects-in-the-universe)*

But you probably did not saw that one:
![Storybook Galaxy](https://thepracticaldev.s3.amazonaws.com/i/2j08x0dpfhfpwhbu0bwg.png)
*Storybook galaxy*

No, this is not Andromeda Galaxy. This is a dependencies galaxy of [Storybook](https://github.com/storybookjs/storybook). Storybook depends on more than 700 packages, which are connected by almost 1300 connections, and based on more than 10 different licenses. It is "just" 117 MB of code, but the amount of packages scares me. What's more, there are addons for the Storybook. In order to use it with React ([@storybook/react](https://www.npmjs.com/package/@storybook/react)) you have to install at least 1450 packages! 

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/t34rqhwu57pmmyetsu7s.gif)

 
  
Recently, I have been looking for a simple cli tool for deleting files by the glob pattern. There a few options, so I compared the *weight* of the first few:

| name   |dependencies tree nodes | size |npms.io score|
|--------|-----|----|---|
| rimraf |12   |170 kB|82|
| trash-cli |179   |2.3 MB|71|
| del-cli|94   |2.1 MB|72|

Hello, I just want to delete some files, I do not need the [Spaceball One] (https://en.wikipedia.org/wiki/Spaceballs), for this task.

![Spaceball One](https://thepracticaldev.s3.amazonaws.com/i/tctd4b1hgwmg8rqf92ji.jpg)
*Spaceball One transformed into Mega Maid, in the mission ["Vacu-Suck"](https://www.youtube.com/watch?v=O7aeWQCF1jM)*

I know there are tools that try to solve the problem like [yarn](https://yarnpkg.com/lang/en/), but it would be better to do not create that problem at all. Let's consider that we have to pay for the time and disk space for every environment where our package is used, CI, my next desk colleague, a developer from another place in the world. Do not use the Spaceball One if you do not need it, do not create the Spaceball One if it is not your goal. Remember, every time you add a dependency, anyone who uses your code adds it as well. 

There are some useful tools which we can use to evaluate *weight* of packages. For some time I have been using:
* [npm.anvaka.com](https://npm.anvaka.com/) - Visualization of npm dependencies
* [NPMGraph](http://npm.broofa.com/) - Visualize NPM Module Dependencies
* [bundlephobia](https://bundlephobia.com/) - Cost of adding a npm package to your bundle
* [npms.io](https://npms.io/) - A better and open source search for node packages

Do you know any other tools? Do you have any advice on how to prevent the project from becoming a GIANT?

P.S. I know that rimraf, trash-cli and del-cli are "different" :)