Using Node.js to Host Development Web Services

One of the cool things about Node.js, besides the fact that it's fast and scalable, is that it's extremely easy to setup and get running. In a couple of minutes you can get a fully operational web server running with minimal code. I've been playing around with the Express library and it makes developing Node.js app sooo much easier. It's early but I'm really impressed with it so far. Check out this screencast for a 5 minute overview.

One use case that we've come across is to use Node.js to mock up web services for development and testing. It's easy to put together a small app the stubs out a return structure to get your POC up and running quickly. How many times have you wanted to test your Apex callouts but the web service wasn't finished or stable yet? Now you can setup a quick Node.js app on Heroku that returns dummy data, develop your callouts and then switch to the production endpoint when available. This use case is extremely useful when developing mobile apps as you can run the Node.js server locally while developing with your simulator! (Another great idea from Romin).

We've found a really cool use case for Node.js at CloudSpokes. Most of our challenges use some sort of backend datastore or API and this can become tedious when working on jQuery, Rails or HTML challenges where the developer really doesn't care where the data comes from. Typically their first step in development is authenticating to the API which is a pain when all you really care about is the UI. Now with Node.js we've decoupled the frontend and backend requirements. We've made available a little Node.js app with resources that simply return JSON in the structure that they'd receive from actual calls to They can modify the Node.js app to return different hashes or extend the app to simulate different calls if needed. Now the developers don't have to worry about authenticating to and we don't have to setup an org, enter dummy data and configurations and provide them access. Birds are chirping, the sun is shining and everyone is happy.

The source code for the CloudSpokes Node.js devserver is available at github and you can run the app on heroku.

James Ward has a great article about getting a Node.js app up and running on heroku. It's a little long if you are familiar with Heroku but it's well worth the read. Make sure you don't skip the section about configuring your app to listen on the port defined by Heroku's environment variables.