Loading
Loading
  • Home

  • Engineering

  • Engineering insights

Engineering insights

2 min read

First Time Node.js or: How I Built a Simple Instant Message API in an Evening

By Bryan Helmig · February 3, 2012
A yellow rectangle with dotted lines running through it.

With the news that Tropo is shutting down their instant messaging API, we're in a pickle. We're already using IM to get instant notifications of the things that are important to us internally, and we have a bunch of people using it too.

But now what? Well, we do what any self-respecting software engineer does: we build one ourselves!

Project requirements.

All we really need is the ability to send out notifications via OSCAR (which is ) and Jabber (which covers among others). That makes it a lot easier to get started, as we won't be worried about that nasty back-and-forth logic that is the hallmark of a bot. Its just one way, out.

Further, we need to be able to interact with it via a simple REST API, that way we can plug it in along side the dozens of other services we natively integrate with. Not that complicated it would see.

Choosing the tech.

I'm used to Python and Django, so my first though was Twisted, a non-blocking server written in Python. As I started to dig around, I noticed that Twisted is no lightweight beast. The XMPP (Jabber) and AIM protocol was there with Twisted Words, but it wasn't the cleanest. It would probably work, but I was fighting it and the learning curve was steep.

So I explored some of the other options like Ruby's EventMachine and Node.js. EventMachine seemed awesome (I'm a bit jealous it isn't a Python project...) but my Ruby chops are horrible. That would have ended in frustration.

However, Node.js had promise. I mean, I know Javascript fairly well and there were plenty of libs to handle OSCAR and XMPP. So I thought, "Why not?". I figured I would just spend a couple hours and see if I want to use Node.js to build it. Away I went...

Spoiler: those couple hours I set aside to learn Node.js left me with... a finished product. Wow!

Getting started.

First thing was first: install Node. I'm on a Mac, so using brew: brew install nodejs. As always, brew made that easy. I had known about npm, the pip of the Node world, so I installed that too according to their docs: curl http://npmjs.org/install.sh | sh. Easy.

Let's try something that I am familiar with: a single endpoint API. Easy, right? So, having heard of the Node web framework express at a talk given by local good fellow James Carr, I installed it globally (assuming that meant system wide): npm install -g express. Easy again.

I also wanted to use Coffeescript, so using coffee script (which apparently is the new hotness) npm install -g coffee-script. Easy again. After that a simple command compiles to js: coffee --watch --compile index.coffee, which you run with node: node index.js.

Disclaimer: I had used Coffeescript before, so my Node virginity isn't as pure as I've suggested.

The build.

Then I just followed the express docs to get something logging to the console (baby steps, right?):

Get productivity tips delivered straight to your inbox

We’ll email you 1-3 times per week—and never share your information.

Related articles

Improve your productivity automatically. Use Zapier to get your apps working together.

Sign up
A Zap with the trigger 'When I get a new lead from Facebook,' and the action 'Notify my team in Slack'