I am trying to subscribe to a SalesForce topic from a Node.js server using the code provided in the documentation of JSForce:
conn.streaming.topic("InvoiceStatementUpdates").subscribe(function(message) {
console.log('Event Type : ' + message.event.type);
console.log('Event Created : ' + message.event.createdDate);
console.log('Object Id : ' + message.sobject.Id);
});
However, I am getting an error location is not defined
[1552904103100] ERROR (13143 on myuser): location is not defined
ReferenceError: location is not defined
at Object.parse (/home/myuser/projects/my-project/node_modules/faye/src/util/uri.js:36:36)
at klass.initialize (/home/myuser/projects/my-project/node_modules/faye/src/protocol/dispatcher.js:21:28)
at klass (/home/myuser/projects/my-project/node_modules/faye/src/util/class.js:13:28)
at Function.Dispatcher.create (/home/myuser/projects/my-project/node_modules/faye/src/protocol/dispatcher.js:179:10)
at klass.initialize (/home/myuser/projects/my-project/node_modules/faye/src/protocol/client.js:44:35)
at klass (/home/myuser/projects/my-project/node_modules/faye/src/util/class.js:13:28)
at Streaming._createClient (/home/myuser/projects/my-project/node_modules/jsforce/lib/api/streaming.js:127:20)
at Streaming._getFayeClient (/home/myuser/projects/my-project/node_modules/jsforce/lib/api/streaming.js:148:42)
at Streaming.subscribe (/home/myuser/projects/my-project/node_modules/jsforce/lib/api/streaming.js:185:25)
at Topic.subscribe (/home/myuser/projects/my-project/node_modules/jsforce/lib/api/streaming.js:41:26)
Digging into the problem I found a comment in Github stating that faye , which is a direct dependency of JSForce, is meant to be used in browser apps only. However, JSForce is expected to work both in client and server sides.
Any ideas about why this could be happening would be appreciated. Thanks!
I finally fixed the issue making an explicit login()
call before attempting the streaming
function.