title: Right way to connect to Google Cloud SQL from Node.JS
body: <p>I followed the example on how to set up Node.JS to work with Cloud SQL, and generally got it to work, but with some workarounds on how to connect to the SQL server. I am unable to connect in the proper way passing the <code>INSTANCE_CONNECTION_NAME</code> to the <code>socketPath</code> option of the <code>options</code> variable for the <code>createConnection()</code> method. Instead, as a temporary workaround, I currently specify the server's IP address and put my VM IP address into the server's firewall settings to let it through.</p>
  
  <p>This all works, but I'm now trying put it together properly before publishing to AppEngine.</p>
  
  <p>How can I get it to work?</p>
  
  <p>The following code works fine:</p>
  
  <pre><code>function getConnection ()
  {
    const options = 
    {  
      host: "111.11.11.11", //IP address of my Cloud SQL Server
      user: 'root',
      password: 'somePassword',
      database: 'DatabaseName'
    };
    return mysql.createConnection(options);
  }
  </code></pre>
  
  <p>But the following code, which I am combining from the <a href="https://cloud.google.com/nodejs/getting-started/using-cloud-sql" rel="noreferrer">Tutorial</a> and from the <a href="https://github.com/GoogleCloudPlatform/nodejs-getting-started/blob/master/2-structured-data/books/model-cloudsql.js" rel="noreferrer">Github page</a>, which is referred to in the Tutorial, is giving errors:</p>
  
  <pre><code>function getConnection ()
  {
    const options = 
    {  
      user: 'root',
      password: 'somePassword',
      database: 'DatabaseName',
      socketPath: '/cloudsql/project-name-123456:europe-west1:sql-instance-name'
    };
    return mysql.createConnection(options);
  }
  </code></pre>
  
  <p>Here's the error that I'm getting:</p>
  
  <pre><code>{ [Error: connect ENOENT /cloudsql/project-name-123456:europe-west1:sql-instance-name]
    code: 'ENOENT',
    errno: 'ENOENT',
    syscall: 'connect',
    address: 'cloudsql/project-name-123456:europe-west1:sql-instance-name',
    fatal: true }
  </code></pre>
  
  <p>What am I doing wrong? I am concerned that if I publish the app to AppEngine with the IP address, I won't be able to allow the incoming traffic into the SQL server?</p>