You will need to learn javascript / nodejs and event programming.
query.on('row', function() { /*CODE*/ }) means: "when the line is being read, execute the CODE."
It is asynchronous; therefore, query.on () logs the event and returns.
So when console.log(rows) is called, the rows are still empty, because the "row" event has not yet been triggered in the request.
You should try putting 'console.log (rows)' in the body of the query.on ('end') event handler.
Throughout the code, you also need to write console.log . You will see an asynchronous thing.
Drasill
source share