/ Open Source

creating my first open source package

I think building a project or tool that others can use and benefit from is a goal for every developer out there. Being able to create something that is so cool, or easy to use, that a large group of people choose to use it must be amazing. But even better than that, what if those people like it so much that they want to give back?

That was my goal, and still is. I've always wanted to create an open source project or tool that people would want to use, and end up liking so much that they collaborate on new features, report bugs and help others wanting to use it as well. The wonderful thing about being a web developer in this time where everything is open source and the community is constantly evolving is that this goal could be a reality for almost anyone.

One day I had decided I was going to make an open source project, I didn't know what I was going to make, but I was going to make one, and I didn't care who used it, I just wanted to share my code with someone else. I sat there for a few hours, going back and forth between projects, reddit and Twitter trying to think of ideas. I couldn't think of anything worth while, the obvious questions ran through my head. What would people even want to use? Why would they use mine instead of someone elses? What kinds of things don't already exist? Is this even a problem other people have? Coming up with an open source idea seemed impossible, and I questioned how projects like React, RxJS, Redux and more ever became an idea. Needless to say, I did not create an open source project that day.

Weeks later, I was working on a project and we needed to mock data for the front-end for unit tests. We searched around a little bit and couldn't find anything that really suited our needs, most other libraries similar relied on back-end JS models which we didn't have. I laid out an insanely simple prototype to get going with it. Right after I sat back and zoned out, then it clicked, this is my open source project! I re-wrote the tool a lot cleaner that night with error handling, unit tests and a better structure. Then I was stuck. What do I do next? Is this even good enough for open source? What if my code is bad? What if people don't even need this? I sat there, trying to think of all these features I absolutely needed to add to make it perfect. As I did this I realized that none of this I actually needed, and that I would never be able to make the tool perfect, that I would never believe that it could just be ok.

Finally I said screw it, lets put this thing on npm. I didn't care if it got 10000 downloads, or 10. I realized that even if it wasn't going to be some crazy big package, somewhere, someone would have a similar problem, and would look for a solution and maybe I can just help those few people. I stopped caring whether or not my code was perfect, in my head it was never going to be, and I accepted that. I realized that no project really starts off as this big perfect project with a perfect structure and code base. React Router started off as a personal tool and turned into the biggest router for React, other major libraries and frameworks started out of hackathons, how could those be perfect out of the box?

So I opened up hyper and cd code/basic-factory then typed npm.. but now what? How do I even do this? Since developers are basically just masters of Google, I anxiously typed "how to publish npm module" into the search bar. Out popped 1000s of results, but obviously stack overflow and medium posts were the first results. I clicked the first medium article (blogs tend to be my go to if available) which led me to How to Create and Publish Your First Node.js Module. I quickly followed the steps and BAM, holy shit, my code is available publically, on the world's largest software registry.

I decided it'd be a good idea to install my package and make sure it works properly, so I did that, followed my own installation and usage guide, and it broke. All of my fears that I had swept under the rug came back out. What have I done? I've published a package that doesn't even work. Luckily, packages on npm don't magically get installed everywhere when you first upload them, so no biggy. I realized that for one, I can't just put ES6 code that isn't compatible on npm since some people might run it elsewhere that cannot use that, so I installed babel. Then that was a whole other process of questions and googling. "How to make build with npm?" led no where, basically just people showing you how to use npm scripts. I ended up realizing that when you do npm publish, if you have a build script, it will be ran. After all this, I installed my package again, and BAM, it works! This is amazing, I have written code that solved a problem I had, and now it might help other people solve the same problem!

My first npm package, called basic-factory is now up on npm, available at https://www.npmjs.com/package/basic-factory. Some days it gets 10 downloads, others it gets 0. That doesn't bother me, maybe those 10 people it worked for, maybe it didn't. If it did I hope they contribute back to it, as I always wish to do for projects I use. I will continue to build out features that I like, and improvements that I see. In the end I basically came to the conclusion that making an open source package doesn't mean revolutionizing front-end development. Creating an open source package can just mean publishing code that solved a problem you had, hoping it solves that for others as well. It also doesn't need to be perfect. Nothing is going to be perfect, everything in the world always has room for improvement, thats just the nature of things, life would be boring if everything was perfect.

Anyways, thanks for reading all these words. Hope you enjoyed my experience, and maybe you learned something or have found some motivation to create your own package! If you do, shoot me a tweet at @bkd705! I'd love to see who read my article and if it helped!