Fight Recap: NodeKO

September 3rd, 2010

This past weekend I had the honor of participating in the fearsome Rocky-IV-style hackathon that was Node Knockout. For those who may actually have a life: Node Knockout was a 48 hour competition featuring teams of hackers each pecking away at a web application that should be somewhat complete-ish after at the end of the two days. In our case, we tried to build a fairly full-feature music player in 2 days (yeah lets see how that turned out)…

Ok, so if you followed the previous link and checked out our app, you’ll see that it’s somewhat pretty (for a ripoff), and barely functional! Man we rock… but really, the competition wasn’t just about winning for our team as much as it was about fiddling around with some new JavaScript hawtsawce. So here’s what I learned:

Pick your 48 hour project Wisely

Yeah, so our idea was to actually build a NodeJS backend which could scan the directories input by the user, read the id3 tag info from the files within those directories (as a start, we could support ogg and flac and other format metadata schemes later), and then put the metadata into a CouchDB.

Then the client could connect to your server, grab the catalog from NodeJS, and play songs that NodeJS would convert on the fly into the proper format for your browser depending on capability (probably through a child process exec to some other encoder — haven’t figured that part out yet).

Unfortunately, we hit a snag on step 1 of this process: reading the data from an id3 tag, which is binary data stored at the beginning on an mp3 file. Node can read streams of data, like so:

  var s = fs.createReadStream(file, {start: 1, end: 2});

  s.on('data', function(data){
    console.log(data.toString());
  });

This is actually the code I was using to check whether a particular file begins with “ID3,” which would thus signify ID3 version 2 data. All the fun technical details behind ID3 can be read about here: http://www.id3.org/Developer_Information

But this is about when things started to break down. After this, and I’m literally talking about the first 10 bytes here, became totally beyond my grasp for a 48 hour competition. WTF does this mean, for example:

The ID3v2 tag size is stored as a 32 bit synchsafe integer (section
6.2), making a total of 28 effective bits (representing up to 256MB).

I mean, I somewhat get what that’s saying. If you just read section 6.2, you can clear as day see…

All this led me to one conclusion after a few hours: Choose your project wisely. Dylan Bathurst, who I’m officially dubbing my “Node Wingman,” is a Front end guy. I’m a front end guy. We probably should not have picked a project that not only required us to pick up server-side programming, but also get all Computer Science major trying to decipher binary data (I have a degree in Sociology — super helpful for that kind of thing). It seems like a simple game using WebSockets might have been a better call… but oh well, just pick a project that helps you learn Node and plays to your strengths!

Plan a bit in advance…

We did a bit of preliminary planning, but we really didn’t get into the nitty gritty of our roles and responsibilities until the competition began. Not that this isn’t a totally fun way to approach a 48 hour competition, and if you think Animal from the Muppets is the coolest guy ever, then just jumping headfirst into the competition might be the best thing for you.

But, it seemed like some of the best ideas had been well thought out a in advance, including splitting up roles for each team member so they could focus on their tasks. With only 2 days of actual design and programming time, getting the prep out of the way so you can focus on code is clutch.

The community rocks

Yeah, I’m talking to you. I hadn’t spent much time in IRC before that weekend, but I was able to ask questions and get prompt, helpful responses. Plugin creators took their time to explain basic stuff to me, and it was even easy to hit up the creator of NodeJS. Plus, the vibe was just electric. Man, it was just fun being in there with everyone.

I also gotta say that I was really impressed with the Joyent setup overall. Thanks for providing such an awesome platform on which to host the competition!

Even if you don’t know anything about NodeJS, you should still totally participate

I wasn’t completely ignorant of Node, but I’m by no means an expert, and I haven’t built any serious/real apps on it. Heck, I hadn’t even built much of a toy app with it. This was my first real attempt at anything of substance. And even though we didn’t get a fully-functional app going, I learned more in two days than I have in a long time.

I would encourage anyone who has even the smallest inclination to give Node a shot to join this competition next time it comes around. If you haven’t learned Node because you don’t really know what to do with it, this competition ends that excuse! Just dive in. The water is warm — I promise!

The future is lookin pretty good…

And you know what was so cool about this competition? Knowledge wasn’t the best thing I gained. I walked away with a sense of optimism I haven’t felt in a while. When you get into the daily grind, a lot of the knowledge we accumulate seems to be incremental rather than revolutionary. NodeJS is a revolution.

Now, of course, there are a couple of secrets I’ve gotta save for myself until next year to give myself a bit of a competitive edge (heyo!), but I gotta end this post thanking everyone who put the competition together, Joyent again for hosting, the awesome people who were hangin out in IRC, and my buddy Dylan for putting the app together with me! It was a blast, and you’d better believe we’re gonna win it next year, so be ready to bring it!