0

I am writing this function with node.js, inside the function it gives me the right output, but when I try to call it from the outside it gives me undefined. Do you have some idea why it doesn't work?

 var inquinamento=function(){
 connection.query('select livelloInquinamento from livInquinamento;',function(err,rows,fields){
 console.log(rows);
 return rows.livelloInquinamento;
 });
 }
Yun
  • 3,056
  • 6
  • 9
  • 28
g4mv16
  • 1
  • 1
  • Does this answer your question? [How to return the response from an asynchronous call](https://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-asynchronous-call) – Arif Khan Oct 01 '21 at 11:19

1 Answers1

0

can you try this

const data = await connection.query('select livelloInquinamento from livInquinamento');

and data will have row and fields and wrap this line in an async function

Mamta
  • 25
  • 1
  • 6