Recently, Node community was shocked by one guy, who removed all his packages from NPM, and left thousands of developers who used his packages in their project suffering a lot (I’ve Just Liberated My Modules). Surprisingly, one of the interesting package he removed is called ‘left-pad’, which has only 10+ lines, are heavily used by developers with more than 20k downloads per day.

Apart from the discussion on whether this developer should be responsible for his action, another popular discussion going on is do we really need this kind of “one-line” modules? These modules are usually short in LOC, and it only takes several minutes to implement for a developer with some experience. As we see the chaos caused by removing that simple “left-pad” module, why don’t we just implement them ourselves?
There are a lot similar packages like this one, for example:

  • isarray, a 5 lines module to test if the given parameter is an array in JavaScript, has more than 600K downloads per day.

Why there are one-line module?

If you wonder why there are so many popular one-line modules, I think the idea comes from a famous principle in software engineering, “DRY”, which stands for “Don’t repeat yourself”. These small but powerful functions are meant to be used frequently in software projects. So instead of creating these functions over and over again in all your projects, you should save the implementation of the function once, store it somewhere, and use it directly when you need it.
That’s why we usually have utility (helper) functions / common library in large projects, which are this kind of useful functions that are meant to be shared in different components.
Now since the best way to create such helper functions in NPM is to create a package and use it, it’s not a surprise that there are so many these one-line modules.

The reason why these one-line modules are popular at some extent is because of the JavaScript language itself. JavaScript has good parts and bad parts. For example, one of the bad parts is about type. JavaScript’s type is easy to use, but it’s somehow very tricky, especially when you want to check the type for the input. For example, Array in JavaScript sometimes will be treated as special Object, which makes it difficult to check if an input is an array. That’s why you will to use isarray module because once you require the package in your project, you don’t need to worry about that headache anymore. I think using external modules greatly makes developing easier. You don’t need to worry about these small details, instead you could just focus on your core implementation. If you need some helper functions, just require it in your project!

Do you make your own shoes? No, you buy them in a store. Most don’t care how the shoe is made. Just how good it fits.

As node package is usually highly modular, plus the complex dependencies system brought by NPM, it’s common that such small modules are downloaded thousands of time every day.

The real problem

I think this also showed a problem in the node ecosystem: there are no standard common libraries like Apache commons library or Google Guava, which is a single collection of all helpful modules like these one-line modules (loadash is good, but not enough). Developers need these common helper functions, and these helper functions are small modules, and we need to include all these modules in our projects. This Snowball effect will eventually caused the cause that small modules are required by thousands of bigger modules. Once it gets removed or has some bugs, whoever requires it will suffer as well.