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