title: TypeError: Cannot call method 'query' of null - when calling pg.connect with Heroku node.js
body: <p>I am encountering an issue connecting to a Heroku postgres database via Node.js. I have found one other instance of somebody experiencing this issue but their suggestion does not work in my case.</p>
  
  <p>I define var DB_URL to be the full Postgres database URL that is stored by Heroku. I do this because process.env.DATABASE_URL is not defined. (This was the suggestion of the other stack overflow post).</p>
  
  <p>The code attempting the connection is:</p>
  
  <pre><code>pg.connect(DB_URL, function(err, client) {
      client.query( ... )
  </code></pre>
  
  <p>When running foreman:</p>
  
  <pre><code>client.query('INSERT INTO bookmarks (username, title, image, url) VALUES (       
  ^
  TypeError: Cannot call method 'query' of null
  </code></pre>
  
  <p>Where by null it is referring to the client object that is meant to be passed into the pg.connect anonymous function.</p>
  
  <p>Advice appreciated, I've looked high and low around the Heroku docs and Googled-a-plenty to no avail.</p>