Skip to content
 

Writing a PaaS (using Node.js) in 1 week – Tuesday

This is a continuation of the post Writing a PaaS (using Node.js) in 1 week – Monday.

Well I’m going to call Tuesday done. The Service Registry is written and installed on my server. Source code is at https://github.com/perfectapi/node-paas-registry.  As with all perfectapi APIs, there is an automatic test app page.  I’ve exposed this one to the Internet, at https://services.perfectapi.com/paas/registry/testapp/

So I’m on target, but it was a rough day.  My first challenge was Redis.  I’ve not used it before, and there was a learning curve involved before I could effectively use it.  I used the node-redis package to access it, and that package worked well.  It was just hard, trying to learn all of the commands, and when to use sets or hashes or whatever.  That ate a lot of time.

My next challenge was the async nature of the node-redis client.  Its fine if you’re just doing one thing, but I had a scenario that went like this:

  • open a connection to the database
  • get the set of instance ids by service name (via callback)
  • for each instance id, get the full instance object (via callback), and if it matches some additional criteria then do something with it and stop processing
  • close the connection to the database

The problem was that this is callback hell.  I couldn’t even figure out where to close the connection.  A little research found me the async package, which was a lifesaver.  Once I started using that, it became very natural to solve the problem.

Finally, I had some problems with perfectapi :(  Required parameters are supposed to validate, but they do not seem to be doing so.  I’ll have to take a look at that separately.

Anyway, lets hope tomorrow goes smoother…

Leave a Reply