title: Cannot read property 'query' of undefined in Node & Postgresql
body: <pre><code>const pool = new pg.Pool(config);
  var tablename = req.body.tablename;
  
  pool.connect(function (err, client, done) {
      var query_get_value = 'SELECT * FROM '+ tablename;
      client.query(query_get_value, function (err, result) {
          done();
          if (err) {
                  throw err;
          }
          var rows = result.rows;
  .....
  </code></pre>
  
  <blockquote>
    <p>this code runs correctly for a while, but a few seconds later, I received following errors:(I call this function repeatedly on the view side using setInterval function)</p>
  </blockquote>
  
  <pre><code> client.query(query_get_value, function (err, result) {
                     ^
  
  TypeError: Cannot read property 'query' of undefined
      at /var/node_project/controllers/index.js:630:10
      at client.connect (/var/node_project/node_modules/pg-pool/index.js:219:9)
      at Connection.connectingErrorHandler (/var/node_project/node_modules/pg/lib/client.js:123:14)
      at Connection.emit (events.js:127:13)
      at Socket.&lt;anonymous&gt; (/var/node_project/node_modules/pg/lib/connection.js:117:12)
      at Socket.emit (events.js:127:13)
      at addChunk (_stream_readable.js:269:12)
      at readableAddChunk (_stream_readable.js:256:11)
      at Socket.Readable.push (_stream_readable.js:213:10)
      at TCP.onread (net.js:598:20)
  </code></pre>