title: Node.js Count Query
body: <p>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,</p>
  
  <pre><code>    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);
  </code></pre>
  
  <p>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?</p>
  
  <p>Thanks in advance.</p>