title: node.js, pg, postgresql and insert queries (app hangs)
body: <p>I have the following simple node application for data insertion into postgres database:</p>
  
  <pre><code>var pg = require('pg');
  var dbUrl = 'tcp://user:psw@localhost:5432/test-db';
  
  pg.connect(dbUrl, function(err, client, done) {
      for (var i = 0; i &lt; 1000; i++) {
          client.query(
              'INSERT into post1 (title, body, created_at) VALUES($1, $2, $3) RETURNING id', 
              ['title', 'long... body...', new Date()], 
              function(err, result) {
                  if (err) {
                      console.log(err);
                  } else {
                      console.log('row inserted with id: ' + result.rows[0].id);
                  }
  
              });
      }
  });
  </code></pre>
  
  <p>After I run node app.js in terminal it inserts 1000 rows into database, then application hangs, and it do not terminates. What I am doing wrong? I have looked into pg module examples but didn’t spot that I’m doing any thing differently…</p>