It might sound ridiculous at first to publish tiny modules on NPM / GitHub.
parse-time for example is just three lines of code.
You can just write functions like these quickly yourself, right?
You probably agree that writing duplicate code is bad and you want to reuse as much code as possible. If you write a tiny function in a big project and a similar one in another, you write duplicate code.
This might not sound much, as you can just copy and paste these few lines. However, what if you used that code snippet in a lot of projects. In some projects you’ve even made some performance improvements. All of a sudden you find a bug. One that you haven’t found before, but using this function in lots of projects finally revealed it. Patching all your projects is going to be a nightmare!
So these are my thoughts on why I started making micro node modules:
- You are able to develop and test a single function in a small and controlled environment.
- Using a module repository like NPM’s means you have only one place to fix or update code. And it allows you to easily update it on all of your projects.
- Publishing it as open source module, means more users will use your code, which in turn means more bug fixes, performance improvements or security updates.
Solve a problem once, write a module, and solve other problems. Don’t solve the same issues over and over again!
Of course there are also drawbacks to this. When using tiny modules you need to handle installing and updating them. Also every dependency might come with a large dependency tree that might add more code to your project as expected.