No response object with http in / http out

#1

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;

0 Likes

#2

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.

0 Likes

#3

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!

0 Likes

#4

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.

0 Likes

#5

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

0 Likes

#6

Nick,

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

image

@cymplecy: FYI

0 Likes