No response object with http in / http out

I'm new to node-red and testing a function node to return data from sql server via sequelize and http input / http output nodes. Data is returned to the function.

My impression is that node.send is to be used for aync operations such as this, but I can't find a way around the "No response object" error.

Any suggestions?

Function Code

var Sequelize = global.get('sequelize') //require('sequelize');
var sequelize = new Sequelize('my_db', 'username', 'password', {
  host: 'mydb.database.windows.net',
  dialect: 'mssql',
  pool: {
    max: 5,
    min: 0,
    idle: 10000
  },
  dialectOptions: {
    encrypt: true
  }
});

sequelize
  .authenticate()
  .then(() => {
      
        // var result = 'Connection has been established successfully.';
        // node.send({payload:result});
      
      sequelize.query("select top 10 * from DRAGDROPITEM", { type: sequelize.QueryTypes.SELECT}).then(rows => {
          
             node.send({payload:rows});

        })

  })
  .catch(err => {
      
    var result = 'Unable to connect to the database: ' + err;
    // node.send({payload:result});
    
  });

return;

Hi @johntalbott

The HTTP In node sends its message with the msg.res property. This is the response object that must reach the HTTP Response node so the request can be responded to.

With you're current code you are not passing on the property from your function. Where you have node.send({payload:rows}); it would be better to do:

msg.payload = rows;
node.send(msg);

In other words, send on the message the Function received, but with its payload updated.

2 Likes

That did it. The documentation threw me a bit. It makes sense now that you explained it.

A couple follow on questions ...

  1. You referred to the approach you shared as "better" way. Is there a "best" way?

  2. What is the use case for node.send example as explained in the documentation?

doSomeAsyncWork(msg, function(result) {
    node.send({payload:result});
});
return;

Thanks!

For the specific task of sending the message, that approach is the 'right' way of doing it.

To be honest, we should update the docs to use the pattern of reusing the received message rather than creating a new message.

1 Like

Sounds good. I have to admit the current documentation had me staring at my computer screen for last day wondering what I was doing wrong.

Thanks again

Nick,

Thanks for the reminder.
I have now also added these guidelines in the wiki of the Blockly node:

image

@cymplecy: FYI

Hello @knolleary,
I'm using the same way as you mention. But seems like not getting the response.

When I tried to set http response at the same place of debug:2 node. At that time I can get the response.
But when I tried to set function between (bellow is the content of the function node). that time I can not get the response.

msg.payload = {'a':"divyesh"};
node.send(msg);

Can you please help me in that case!