Node demo that streams newly created Account records in Salesforce.com to the browser using socket.io. You can run the demo by opening two browsers:
- salesforce CRUD demo with Node - Create a new Account record in this app.
- node-streaming-socketio demo - New Account record are streamed to this app and display in the browser using socket.io.
These will be automatically installed when you use the npm installation method below.
- express - framework
- nforce - REST wrapper for force.com
- jade - the view engine
- faye - a publish-subscribe messaging system based on the Bayeux protocol.
- socket.io - WebSocket protocol for simplify bi-directional communication over HTTP
Setup a new Remote Access to get your OAuth tokens. If you are unfamiliar with settng this up, see 4:45 of my Salesforce.com Primer for New Developers. For your callback, simply use: http://localhost:3001/oauth/_callback
Create a new PushTopic from the Developer Console in your org with the follow. This will setup the endpoint for faye to listen to:
PushTopic pt = new PushTopic();
pt.apiversion = 24.0;
pt.name = 'AllAccounts';
pt.description = 'All new account records';
pt.query = 'SELECT Id, Name FROM Account';
insert pt;
System.debug('Created new PushTopic: '+ pt.Id);
You can also set up PushTopics using the Workbench.
From the command line type in:
git clone https://github.com/jeffdonthemic/node-streaming-socketio.git
This will clone this repo locally so you simply have to make your config changes and be up and running. Now replace your OAuth tokens and credentials in the config.js file.
cd node-streaming-socketio npm install # install all of the packages from the package.json file node app.js # start the server
Update line 9 in views/layout.jade to point to the correct URL.
Point your browser to: http://localhost:3001