Weapons of choice
I still remember my first conversation with our architect when I joined Yahoo! I had just introduced myself. As soon as I told my name, he said, “Ah! I have heard about you. They tell me you have opinions about everything!” He definitely thought me as a bit of Clouseau.
Last month, I worked on a Nodejs project in my freetime — hattira. It is a community driven listing of events in a city. The idea was to answer the question — what is happening in city X? I have a few takeaways from that exercise that I think maybe interesting.
One of the Aha! moments was when I did the first deploy on Heroku. It was a one step deploy that just worked! In addition, a couple of other things really stood out. I was able to follow logs and see what was happening with a simple — heroku logs -t — just like in a terminal. There is even documentation on Heroku website about forwarding the logs to an external server so you can run all types of analytics later.
The other zen moment was how they allowed ‘console’ access to the server instance. One of the things I wanted to do after my deploy was to populate the Mongodb instance with a set of cities. This was a one time load script that had to be run before starting my app. And this was possible with the — heroku run — option. I just had to create a node script that loads the cities and call that with — heroku run node loadCities.js.
The problem is also idiomatic of what we do in a request-response cycle of a web app. We do a few queries against the datastore and serve the response. Async nicely handles this problem and we can avoid having a long nested sequence of callbacks with error handling sprinkled between other code.
There are other libraries that I used for their utility and clean, modular code. Passportjs is probably the default library everyone uses for node projects requiring (social) authentication (Facebook,Twitter, etc). It is very modular. I only used passport and passport-facebook. I used a template project that gave a great platform to get started quickly and easily.
Lastly, the one thing that still rankles are the tests. While — npm test — works, it is not covering as many scenarios as I want. I have some difficultly in writing tests for the case when the user is logged in. That will be a task for one of these weekends.