CloudSQL connection issues with deployed Bookshelf tutorial app (App Engine/NodeJS)

1,170 views
Skip to first unread message

John Hamm

unread,
Mar 28, 2017, 9:10:19 AM3/28/17
to Google Cloud SQL discuss
I'm trying to learn Google Cloud Platform and going through the Cloud SQL bookshelf app tutorial for NodeJS (https://cloud.google.com/nodejs/getting-started/using-cloud-sql) and had no problem setting up the project, app engine, and running locally with the Cloud SQL proxy. But when deployed, I get an error (connect ECONNREFUSED 127.0.0.1:3306) when loading the app URL ([PROJECT_ID].appspot.com).

I searched for fixes and found some saying that the issue is that the NODE_ENV being looked at in the model-cloudsql.js checks to see if it is "production", but nowhere else is it defined as that, so it is trying to use localhost. So I tried adding that to the config.json and adding to env vars in config.js, and deploying, but then I get a different error (connect ENOENT /cloudsql/bookshelf-nodejs-tutorial:us-central1:bookshelf-mysql). So at least it looks like it is using the socketPath, but I can't figure out where to go from here to get the app working.

Here's some of the code I changed:

config.json:

{
 
"GCLOUD_PROJECT": "************************",
 
"DATA_BACKEND": "cloudsql",
 
"MYSQL_USER": "****",
 
"MYSQL_PASSWORD": "*******",
 
"INSTANCE_CONNECTION_NAME": "bookshelf-nodejs-tutorial:us-central1:bookshelf-mysql",
 
"NODE_ENV": "production"
}


config.js:

'use strict';

const nconf = module.exports = require('nconf');
const path = require('path');


nconf
 
// 1. Command-line arguments
 
.argv()
 
// 2. Environment variables
 
.env([
   
'DATA_BACKEND',
   
'GCLOUD_PROJECT',
   
'MONGO_URL',
   
'MONGO_COLLECTION',
   
'MYSQL_USER',
   
'MYSQL_PASSWORD',
   
'PORT',
   
'NODE_ENV'

 
])
 
// 3. Config file
 
.file({ file: path.join(__dirname, 'config.json') })
 
// 4. Defaults
 
.defaults({
   
// dataBackend can be 'datastore', 'cloudsql', or 'mongodb'. Be sure to
   
// configure the appropriate settings for each storage engine below.
   
// If you are unsure, use datastore as it requires no additional
   
// configuration.
    DATA_BACKEND
: 'datastore',

   
// This is the id of your project in the Google Cloud Developers Console.
    GCLOUD_PROJECT
: '',

   
// MongoDB connection string
   
// https://docs.mongodb.org/manual/reference/connection-string/
    MONGO_URL
: 'mongodb://localhost:27017',
    MONGO_COLLECTION
: 'books',

    MYSQL_USER
: '',
    MYSQL_PASSWORD
: '',

   
// Port the HTTP server
    PORT
: 8080
 
});

All other files remained the same. Any help would be appreciated so I can move on to the next sections of the tutorial.

https
://[YOUR_PROJECT_ID].appspot.com

https
://[YOUR_PROJECT_ID].appspot.com

https
://[YOUR_PROJECT_ID].appspot.com

https
://[YOUR_PROJECT_ID].appspot.com

Samuel Kurland

unread,
May 17, 2017, 7:08:24 PM5/17/17
to Google Cloud SQL discuss
I ran into the same problem and found the answer here. All I had to do was enable the Cloud SQL API. Also, check the error logs for startup errors:
 
gcloud app logs tail -s default

Here are the first three lines of my logs before I actived the API:

2017-05-17 21:49:32 default[20170517t144427]  2017/05/17 21:49:32 Ready for new connections
2017-05-17 21:49:32 default[20170517t144427]  2017/05/17 21:49:32 errors parsing config:
2017-05-17 21:49:32 default[20170517t144427]   googleapi: Error 403: Access Not Configured. Cloud SQL Administration API has not been used in project [redacted] before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/sqladmin/overview?project=[redacted] then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry., accessNotConfigured
Reply all
Reply to author
Forward
0 new messages