title: Can't connect to heroku postgresql database from local node app with sequelize
body: <p>I'm trying to connect to a Heroku postgresql database from a local nodejs app with Sequelize. I followed this two guides an everything is working perfectly fine on the heroky server side, but my node app won't connect to heroku when I run it locally on my Mac.</p>
  
  <ul>
  <li><a href="http://sequelizejs.com/articles/heroku" rel="noreferrer">http://sequelizejs.com/articles/heroku</a></li>
  <li><a href="https://devcenter.heroku.com/articles/connecting-to-heroku-postgres-databases-from-outside-of-heroku" rel="noreferrer">https://devcenter.heroku.com/articles/connecting-to-heroku-postgres-databases-from-outside-of-heroku</a></li>
  </ul>
  
  <p>Here is how I start the local app:</p>
  
  <pre><code>DATABASE_URL=$(heroku config:get DATABASE_URL) nodemon
  </code></pre>
  
  <p>Gets me:</p>
  
  <pre><code>Sequelize: Unable to connect to the database:
  </code></pre>
  
  <p>But I get the correct URL by doing this:</p>
  
  <pre><code>echo $(heroku config:get DATABASE_URL)
  </code></pre>
  
  <p>And those commands are working fine:</p>
  
  <pre><code>heroku pg:psql
  psql $(heroku config:get DATABASE_URL)
  </code></pre>
  
  <p>Here is my nodejs code :</p>
  
  <pre><code>var match = process.env.DATABASE_URL.match(/postgres:\/\/([^:]+):([^@]+)@([^:]+):(\d+)\/(.+)/)
  sequelize = new Sequelize(match[5], match[1], match[2], {
      dialect:  'postgres',
      protocol: 'postgres',
      port:     match[4],
      host:     match[3],
      logging: false
  })
  
  sequelize
  .authenticate()
  .complete(function(err) {
      if (!!err) {
          log('Sequelize: Unable to connect to the database:', err);
      } else {
          http.listen(process.env.PORT || config.server.port, function(){
              log('Web server listening on port '+process.env.PORT || config.server.port);
          });
      }
  });
  </code></pre>
  
  <p>I tried to add <code>native: true</code> to the sequelize options, but then I get:</p>
  
  <pre><code>    /Users/clement/Projets/XMM/node_modules/sequelize/lib/sequelize.js:188
        throw new Error('The dialect ' + this.getDialect() + ' is not supported.
              ^
  Error: The dialect postgres is not supported. (Error: Please install postgres package manually)
      at new module.exports.Sequelize (/Users/clement/Projets/XMM/node_modules/sequelize/lib/sequelize.js:188:13)
      at Object.&lt;anonymous&gt; (/Users/clement/Projets/XMM/server.js:17:14)
      at Module._compile (module.js:456:26)
      at Object.Module._extensions..js (module.js:474:10)
      at Module.load (module.js:356:32)
      at Function.Module._load (module.js:312:12)
      at Function.Module.runMain (module.js:497:10)
      at startup (node.js:119:16)
      at node.js:929:3
  </code></pre>
  
  <p>Even after doing:</p>
  
  <pre><code>npm install pg
  npm install -g pg
  brew install postgresql
  </code></pre>
  
  <p>This is working by the way:</p>
  
  <pre><code>var pg = require('pg');
  pg.connect(process.env.DATABASE_URL+'?ssl=true', function(err, client, done) {
      if (err) return console.log(err);
      client.query('SELECT * FROM pg_catalog.pg_tables', function(err, result) {
          done();
          if(err) return console.error(err);
          console.log(result.rows);
      });
  });
  </code></pre>
  
  <p>But i'd rather use Sequelize.</p>