title: Asynchronous calls using postgres as an example in NodeJS
body: <p>When implementing this code (example taken directly from <a href="https://github.com/brianc/node-postgres" rel="nofollow">https://github.com/brianc/node-postgres</a>):</p>
  
  <pre><code>var pg = require('pg'); 
  
  var conString = "tcp://postgres:1234@localhost/postgres";
  
  pg.connect(conString, function(err, client) {
    client.query("SELECT NOW() as when", function(err, result) {
        console.log("Row count: %d",result.rows.length);  // 1
        console.log("Current year: %d", result.rows[0].when.getFullYear());
        //Code halts here
    });
  });
  </code></pre>
  
  <p>After the last <code>console.log</code>, node hangs. I think this is because the asynchronous nature, and I suspect at this point, one should call a callback function.</p>
  
  <p>I have two questions:</p>
  
  <ol>
  <li>Is my thinking correct?</li>
  <li>If my thinking is correct, then how does the mechanics work. I know NodeJS is using an event loop, but what is making this event loop halt at this point?</li>
  </ol>