Getting Started with Node.js (for Cocoa developers)

There are three parts to your iOS or Mac app: design, implementation, and back-end.

Design is what it does, how it works, and what it looks like. Implementation is what you do in Xcode. The back-end is — well, it’s, hrrmmm, something other people do? Or something we just ship without?

What Tim Said

Here’s Omni Group CTO Tim Wood talking about syncing: Own the Wheel. I think this applies to more than just syncing — it applies to whatever back-end services your app needs, even if you’re a solo developer or part of a small shop.

(Unless, of course, you’re writing an app whose reason-for-being is to act as a client for somebody else’s service. Given the experience of Twitter and Google Reader client developers, you might consider this decision carefully.)

There are two pieces of good news. One is that learning this stuff isn’t that hard. The other is that it’s really fun.

Node.js

There are lots of web app frameworks. They don’t all do the same things: you can’t compare apples to apples. Node by itself isn’t even really an app framework — it’s a server framework.

I like it because it’s fast, lightweight, and has wide support. You write code in JavaScript — and, while I don’t love JavaScript, I do like it (to my surprise), and it means one language for server-side and in-browser code.

Node will be instantly familiar to Cocoa developers. It has a main thread run loop. I/O is non-blocking and calls back to your scripts on the main thread. JavaScript has closures (blocks, in our world) which make all this easy.

While Node is cool, it’s not much of a web app framework. For that you need Express. I’ll write about Express in a follow-up. (I’ll also write about npm, the Node package manager.)

Though it’s not Node-specific, The Twelve-Factor App is worth reading for a high-level view of how web apps are built these days. (It’s a website/essay. Not that long. Highly recommended.)

You might think you need to buy a server, or rent a virtual server, to run Node — but that’s actually not true. Plenty of places offer Node hosting, where you deploy your app (via Git, usually) to their server, and you don’t have to worry about security patches and all that stuff. See Heroku, Azure, Joyent, Nodejitsu, and others. (I’ve got nothing against buying or renting servers for other reasons. I’m a fan of Macminicolo.net, for instance.)