title: How to Connect to postgres db from angularjs controller
body: <p>I want to store some user values, name and email, in a Postgres DB on an app hosted by Heroku. This is the code in my controller;</p>
  
  <pre><code>var pg = require('pg');
  ...
  $scope.addUser = function() {
      pg.connect(process.env.DATABASE_URL, function(err, client) {
          var query = client.query('INSERT INTO users (name, email) VALUES (\'' + $scope.user.name + '\', \'' + $scope.user.email + '\')');
  
          query.on('row', function(row) {
              console.log(JSON.stringify(row));
          });
      });
  };
  </code></pre>
  
  <p>I get an error saying that require is not defined, which I know is because it is not supported client side. I tried using browserify on the controller file, then updating the <code>&lt;script&gt;</code> tag in the index.html that sources the file. This leads to another error.</p>
  
  <p>Removing the <code>var pg = require('pg');</code> gives a "ReferenceError: pg is not defined". I just want to connect to the Postgres DB from my app and insert some values. Am I on the right track or should I be going about this differently?</p>