Why I started developing in nodejs again?
Few months back, I started again with nodejs. It all started with Microsoft releasing Typescript. I wanted to learn it and try to use it. So I got back to developing with nodejs.
I started learning nodejs in 2014. I developed a static blog engine in sailsjs. Or at least I tried to. It took me long time to follow the ‘async by default’ feature of nodejs. Even when I understood it, I would forget it in the normal flow of coding. I still persisted in learning nodejs, because everyone was talking about it and I didn’t want to dismiss it because I didn’t understand it.
But then, I dropped it. Wy?
Async by default: This is the biggest stumbling block in learning nodejs. Since I had a decade of experience in Python programming, I found it almost impossible to learn this different mental model. I would write a piece of code, as per Python model, and test it, only to find it doesn’t work because, well, file reading, db operations, anything significant are all async. It was a big hit to my confidence as a programmer.
Callback hell: In those early days callback was the only way to handle async feature. It was neither easy nor pretty. In Python, you can go through a large code block line by line and understand what it does. Not so in nodejs because execution is async. Writing layers of nested callbacks wasn’t so difficult; I could train myself to do it. But the mere thought of going back to that large piece of code block to debug was a nightmare.
Immature Promises libraries: One of the solutions for callback hell was to use a promises library. But in those early days, they were immature. Immature, not only in terms of implementation but also in terms of documentation and code samples for different use-cases. You were jumping from frying pan to fire!
TJ leaving: TJ was a prolific contributor to nodejs. This guy created a webframework, a templating engine, testing framework and so much more. If you wrote a decent nodejs application, you ended up using many of his packages. Wait. Let me rephrase that. You could write a large nodejs application only with packages created by him. He was that prolific. And then one day, he left nodejs community. He published a farewell post where he listed many of nodejs drawbacks. I started doubting future of nodejs seriously after this incident.
Infighting within nodejs: The final nail was put when leading nodejs developers forked it into io.js. Almost the same time, sailjs was also forked due to misunderstanding within the community. I decided enough was enough and moved on.
Few months back, I started again with nodejs. It all started with Microsoft releasing Typescript. I wanted to learn it and try to use it. So I got back to developing with nodejs. There are other reasons too.
Typescript: As I said, the first reason is MSFT releasing Typescript. It seemed well developed and resembled Python in readability. The more I learned it, the more I liked it. I even wrote a beginner’s reference guide.
Truce in the community: Nodejs and iojs merged and started releasing regular updates. This was not a major reason for me to return, but knowing that the future of nodejs is not split across multiple communities is soothing.
Hapijs: Hapijs is a nodejs web-framework created by Walmart. It is modular, secure, and well documented. It is easy to learn. If you are starting in nodejs, I would highly recommend it.
Mature promises libraries: Promises are now built into nodejs. But the bluebird implementation is even better. I still break-up big modules into smaller one, but now I can write
db.read().then().then(), which is much easier mental model.
I have been developing in hapijs with Typescript for the past 2 - 3 months. It has been pleasant beyond my expectation.
Under: #tech , #nodejs , #hapijs , #tsc