We've been working with Node.js quite a bit at CloudSpokes but I hadn't done anything with Force.com and Node.js using their REST API; we've mostly been using our own API. So I thought I would give it a spin and see what it would take to write a small demo app using Node.js, the Force.com REST API, OAuth, Express and Jade for templating.
As it turns out it wasn't that difficult. Salesforce.com has done most of the work writing the REST and OAuth pieces.
So initially I started woking from Josh Birk's FDC-NODEJS-HEROKU repo (don't use this btw). I should have known from the beginning not to use this as the code hadn't been updated in 9 months. Anyway a spent some time over the weekend getting it to work with Express, adding some middleware and rewriting some stuff. Once I finally got it working, I emailed Josh with a question and he informed me that the code was outdated and not to you use it.
Being the cool guy that Josh is, he pointed me to Dave Carroll's rest4dbdotcom repo for the latest and greatest code. This is definitely the repo you want to watch.
So I put together a small demo that allows you to authorize access to an org, get a list of accounts, create new accounts and update existing ones.
Most of the logic for the application is in the main app.js file (below) and you can see that it's pretty straight forward. We set some configuration parameters for OAuth, configure the middleware, create the server and then define the routes that we can call.
I did make a small change for the "/accounts" route in app.js. You'll notice that it delegates to routes/index.js and contains no actual code. When your node application start getting more complex and larger, you'll want to refactor the code out of app.js and into their own routes to make life easier.