title: How to connect Google Cloud SQL from Cloud Functions?
body: <p>I am trying to use <a href="https://firebase.google.com/docs/functions/" rel="noreferrer">Cloud Functions for Firebase</a> to build an API that talks with a Google Cloud SQL (PostgreSQL) instance.</p>
  
  <p>I am using HTTP(S) trigger.</p>
  
  <p>When I white-list my desktop's IP address, I can connect to the Cloud SQL with the function's node.js code from my local machine. But when I deploy, I can't connect, and I can't figure out the HOST IP address of Firebase Function's server, to white-list.</p>
  
  <p>How do you talk to Google Cloud SQL from Cloud Functions for Firebase?</p>
  
  <p>Thanks!</p>
  
  <pre><code>// Code Sample, of what's working on Localhost.
  var functions = require('firebase-functions');
  
  var pg = require('pg');
  var pgConfig = {
    user: functions.config().pg.user,
    database: functions.config().pg.database,
    password: functions.config().pg.password,
    host: functions.config().pg.host
  }
  
  exports.helloSql = functions.https.onRequest((request, response) =&gt; {
    console.log('connecting...');
    try {
      client.connect(function(err) {
        if (err) throw err;
  
        console.log('connection success');
        console.log('querying...');
  
        client.query('SELECT * FROM guestbook;', function(err, result){
          if (err) throw err;
  
          console.log('querying success.');
          console.log('Results: ', result);
          console.log('Ending...');
  
          client.end(function(err){
            if (err) throw err;
            console.log('End success.');
            response.send(result);
          });
        });
  
      });
    } catch(er) {
      console.error(er.stack)
      response.status(500).send(er);
    }
  });
  </code></pre>