A few weeks ago we received a series of questions from the community about using Node.js with Titanium Desktop. Using a remote Node.js server with the Titanium mobile and/or desktop applications is not much different that working with any remote service. Working with a local Node.js server however is somewhat problematic in that most desktop machines do not have a local Node instance. That being said, while Titanium Desktop (as it stands today) does not bundle Node.js that doesn’t mean you can’t. Or at least that was my theory before kicking off a prototype a few days ago.
To make Node.js useful from a local desktop development perspective we need to assure our app always has access to a Node.js instance. To accomplish this I started by compiling Node for OSX and Linux and dropping the resulting binaries into my projects default Resources directory. Items within the Resources directory are bundled with our project when we package for distribution so that solves the first problem. OK so we can distribute Node with the app now, but that is not of much use to us unless we have the ability within our application to pass it a script, create a server, etc.
To demonstrate usage of this I’ve built a simple little Github application. With Node support comes access to the wonderful world of Node Modules. Use can use npm to install modules within a project’s Resources directory just as you would any other Node project. This prototype uses the node-github module to handle interation with the Github API within Node.