Wednesday, February 22nd, 2012

NodeJS with Salesforce

Over the past couple weeks I have had some down time. I have been wanting to take a closer look at node.js ever since it was released as a part the Celadon Cedar stack. If you have used heroku in the past, getting node.js up and running was pretty straight forward. They have a pretty good getting started guide over here: http://devcenter.heroku.com/articles/node-js. Even if you have not used heroku in the past, this guide is right on the money.

As I started to experiment more with node.js, I wanted to be able post data from a node.js application running on heroku to Salesforce.com via the REST API. Fortunately, Josh Birk wrote a nice article on how to use node.js with the new Apex REST (http://blogs.developerforce.com/developer-relations/2011/06/using-nodejs-with-forcecom.html). Leveraging the CRUD methods from node.js REST wrapper that Josh built for APEX REST I was able to easily create records in salesforce. I refactored this code a bit in order to take advantage of (and get more experience with) the out of the box features of express and node-oauth packages.

Using express and the jade view engine with my sample application, I was able to put together a nice little demo app of the crud operations working with SFDC.

The best part of using node.js with express was by simply constructing the name of the form elements to match the name of the fields in the object I was trying to create allowed me to pass request.body to the salesforce rest api and create the object without any object reconstruction on mapping. It is these types of things that make JSON stand out as the best message format around.

Here is a link to the sfdc-node source on github: https://github.com/gidzone/sfdc-node. Please fork away!  If you would like to get started working with this right away please use the source from github.  I had to make a couple changes to the oauth library, which are still waiting to get pulled into the main branch. I’ll post an update when the pull requests have been accepted, so you can easily run npm install sfdc-node.

The sample app can be found here: https://github.com/gidzone/nodejs-sfdc-sample

Share:
  • Facebook
  • Twitter
  • LinkedIn
  • email
  • Print
  • Add to favorites

4 Comments on “NodeJS with Salesforce”

  • TIm Inman September 5th, 2011 9:53 pm

    You had free time? Didnt you just have a kid :) Nice work.

  • Sanjay Gidwani September 5th, 2011 11:41 pm

    Thanks Tim! All those sleepless nights!

  • Josh BIrk September 6th, 2011 12:16 pm

    Looks excellent. You might check out Dave and Pat’s work with Node and Force.com which uses restler for the REST callouts:

    https://github.com/dcarroll/rest4dbdotcom

  • Sanjay Gidwani September 6th, 2011 9:46 pm

    Thanks Josh!

    Dave and Pat’s work looks good! I like how they configured the client id and secret via heroku environment variables.

Leave a Reply

Connect with Facebook