Drupal and Node.js

I’ve been working on a project that required real-time Javascript updates based on user actions (including other users’ actions). At first the only solution I could see was polling the server every second via Ajax, but that (a) was very resource-intensive, (b) didn’t give me as much freedom with the JS as I wanted (though maybe that was my relative lack of experience with jQuery), and (c) though pretty close, wasn’t exactly real-time. I did my best to reduce the computations on the server as well as the bandwidth, but the result was still not that good. I had to find another solution, and I did: Node.js.

I’ve been working on a project that required real-time Javascript updates based on user actions (including other users’ actions). At first the only solution I could see was polling the server every second via Ajax, but that (a) was very resource-intensive, (b) didn’t give me as much freedom with the JS as I wanted (though maybe that was my relative lack of experience with jQuery), and (c) though pretty close, wasn’t exactly real-time. I did my best to reduce the computations on the server as well as the bandwidth, but the result was still not that good. I had to find another solution, and I did: Node.js.

As it happened, there is a Node integration module, but it still meant I had to set up a Node server somewhere. My localhost seemed like the logical place to start, especially since a Mac installer was available to download. The installation process wasn’t too hard; it did force me to dig into the command-liney parts of my Mac, which was a new experience. Likewise, I gave myself a crash course on Apache virtual hosts and iptables and a few related tasks. Problem, I could never get it to communicate with my local Drupal install, and I’m still not sure what I was doing wrong. In hindsight I probably should have taken better notes.

Things went a lot better when I installed Node on the actual production server. Different system, so I had to find different instructions: here for the Node server, and here for the Drupal side of things. And it worked, pretty much right out of the box! I say “pretty much,” since the instructions are kind of incomplete, and in at least one case the automatic config generator was wrong, and I had to tweak the config file manually. I’ll be blogging more about that, as well as raising the issue with the node.js project. As soon as I double-check that it really is an issue.

So yeah, we do live and learn. I’m glad this project pushed me out of my comfort zone and made me learn Linux development… not to say I’d ever do it full-time, but hey, knowledge is never a bad thing.