I am trying to get the total records using node.js. I am facing issue in variable scope. Not sure how to handle this. My sample code is,
var total_records = 0;
var client = new pg.Client(pgConnect);
client.connect();
client.query(count_query, function(err, row) {
total_records = row.rows[0]['count'];
console.log(total_records);
});
console.log(total_records);
It prints right result in query block but print 0 after that block. I want to use its value after client.query block. Is it possible in Node.js?
Thanks in advance.