var nforce = require('nforce');

var org = nforce.createConnection({
  clientId: '',
  clientSecret: '',
  redirectUri: 'http://localhost:3000/oauth/_callback',
  environment: 'production',
  mode: 'single'
});
var TOPIC = 'Event__e';
var REPLAY_ID = -1;
var USERNAME = '';
var PASSWORD = '';

org.authenticate({ username: USERNAME, password: PASSWORD}, function(err, resp){
  if(err) console.log("Error authenticating to Salesforce, " + err);
  if(!err) console.log('Cached Token: ' + org.oauth.access_token);
  var client = org.createStreamClient();
  var accs = client.subscribe({topic:TOPIC, isEvent:true, retry: REPLAY_ID});
  accs.on('data', function(data) {
    console.log("Platform event on topic, " + TOPIC + " detected\nEvent:" + JSON.stringify(data.payload));
  });
});