Home > Enterprise >  When should I create my own module package instead of using other packages?
When should I create my own module package instead of using other packages?

Time:03-19

I'm still a new node js developer, currently building a personal project, and I recently found out that there are open source packages available on npm similar to the thing I'm developing.

These packages carry new advanced concepts that I haven't come up with yet and provide more options than I want, but after thinking, it occurred to me why not develop a package that serves me in my project the way I want instead of using packages where I won't use more than 5% of the functions in my project?

CodePudding user response:

Benefits of using an existing, well-supported module:

  1. You save your development time for things that haven't already been written by someone else allowing you to make faster progress on your project
  2. Well tested by the community (pre-tested code saves you lots of time)
  3. Other people finding and fixing bugs (don't underestimate the importance of this)
  4. The code will likely be kept up-to-date as tech changes over time
  5. Possible community of people to ask questions of that knows about that package

Non-issues with using an existing, well-supported module:

  1. Code size is rarely an issue for server-side nodejs development so the fact that a package may contain extra code that you don't need is generally not a practical issue of any consequence. If code size is paramount (like say you were running on a small, embedded system), then nodejs itself might not be the right environment as it's not exactly compact.

Reasons not to use an existing, well-supported module:

  1. You aren't allowed to use open-source code in your project (but then you wouldn't be using nodejs if that was the case).
  2. No existing module does what you want.
  3. Existing modules that do what you want don't appear to be well supported or have many relevant bugs that have been open for a long time. In this case, it still might be worth if for you to clone the repository and use it as a starting point or learning point for your own module.

I'm still a new node js developer, currently building a personal project, and I recently found out that there are open source packages available on npm similar to the thing I'm developing.

IMO, this is part of the magic sauce of doing nodejs development. The huge repository of open source packages (through NPM) that are so easy to use make your development far more productive than developing everything from scratch yourself.

why not develop a package that serves me in my project the way I want instead of using packages where I won't use more than 5% of the functions in my project?

Unused code doesn't really cost you anything of consequence in a server-side environment. If you really wanted you can use bundlers that support tree-shaking which removes the code you're not using.

The question that really matters is whether an existing module meets your needs or is closest enough that you only have to write a little bit of code in order to use it. If that's the case, then the question becomes this: "Why should I use my precious development time to write a package from scratch when I could use far less development time by using something that is already available for free, is already tested and is already proven and then spend that development time (I would have spent developing that package) on other things that advance my product/service further?

In many ways, this is really no different than using the fs module built into nodejs. You use it because it's already developed and already tested and saves you time over developing your own file access module. Yes, the fs module contains lots of code you may never need, but that's not the question. The question is whether it already contains the code you DO need.

  • Related