External Module in Script Node Not Working

I am using the npm version of n8n and I’m trying to use the JSForce node module in a Script Node (it has more features than the existing Salesforce Nodes).

I already added the module as per the instructions (Configuration | Docs) and I don’t get any errors about missing modules when I run my workflow.

Just to test, I created a Script Node to try to login to Salesforce using JSForce (I have omitted my credentials below for security reasons Document - JSforce):

var jsforce = require('jsforce');
var conn = new jsforce.Connection({
  // you can change loginUrl to connect to sandbox or prerelease env.
  loginUrl : 'https://test.salesforce.com'
conn.login(username, password, function(err, userInfo) {
  if (err) { return console.log(err); }
  // Now you can get the access token and instance URL information.
  // Save them to establish connection next time.
  // logged in user property
  console.log("User ID: " + userInfo.id);
  console.log("Org ID: " + userInfo.organizationId);
  // ...
  return [
  json: {
    userId: userInfo.id,
    orgId: userInfo.organizationId

When I run this - I get a ‘No Data Returned’ error from N8N, and none of the console log messages in the code show up in either my browser Dev Inspector Console or from my terminal where N8N is running.

It’s like conn.login() is not running at all - what’s causing this? Is N8N blocking something or is there another configuration I have to do?

If you run async code you have to return a promise. So if you wrap the conn.login with a promise and that promise resolves then with the data, it will work fine.

1 Like

Thanks - I was originally using a chained promise and for some reason it wasn’t working, I changed it to return only one Promise and it worked after.

1 Like

Great to hear that you got it working. Have fun!