Connection to Mysql from NodeJS on Heroku server

2013-08-24T00:51:26

ANy idea how can I connect from NodeJs to the Mysql ClearDB on Heroku?

I was able to connect to the ClearDB Mysql runing on Heroku from Navicat, I even created a table called t_users. But I'm having problems connecting from NodeJs from Heroku.

This is my code, it is very simple: everything works find until it tries to connect to MySQL

web.js:

var express = require("express");
var app = express();
app.use(express.logger());

var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : 'us-cdbr-east-04.cleardb.com',
  user     : '',
  password : '',
  database : ''
});

connection.connect();

app.get('/', function(request, response) {
  response.send('Hello World!!!! HOLA MUNDOOOOO!!!');
  connection.query('SELECT 1 + 1 AS solution', function(err, rows, fields) {
      if (err) throw err;

      response.send('The solution is: ', rows[0].solution);
    });
});

var port = process.env.PORT || 5000;
app.listen(port, function() {
  console.log("Listening on " + port);
});

This is what I got when I run on the command line: Heroku config

C:\wamp\www\Nodejs_MySql_Heroku>heroku config
=== frozen-wave-8356 Config Vars
CLEARDB_DATABASE_URL: mysql://b32fa719432e40:[email protected]/heroku_28437b49d76cc53?reconnect=true
PATH:                 bin:node_modules/.bin:/usr/local/bin:/usr/bin:/bin

This is the LOG: http://d.pr/i/cExL

ANy idea how can I connect from NodeJs to the Mysql ClearDB on Heroku? Thanks

Copyright License:
Author:「lito」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/18408012/connection-to-mysql-from-nodejs-on-heroku-server

About “Connection to Mysql from NodeJS on Heroku server” questions

ANy idea how can I connect from NodeJs to the Mysql ClearDB on Heroku? I was able to connect to the ClearDB Mysql runing on Heroku from Navicat, I even created a table called t_users. But I'm having
I have a very simple nodeJS app connection to a MySql ClearDB. The first time running it has no problem connection to the DB and executing a simple SELECT but after some minutes the server crash it...
I am trying to get an array of questions and answers stored in a MYSQL database (bluehost) for a quiz nodeJS app (heroku). I have tried using a static IP add on, but I am wondering if it is possibl...
I just installed a NodeJS server on Heroku by walking through the getting started guide (https://devcenter.heroku.com/articles/getting-started-with-nodejs) and I think I did all the steps correctly.
I have written a Nodejs application that I plan on deploying to Heroku. The Nodejs app has mysql package installed and has lot of async query execution. When I one of my query fails and Nodejs throws
My question is similar to this post but the solution didnt work for me probably because im using a different type of mysql connection (pool). This is my code: let config= { host: '***',...
I have a NodeJs backend hosted on Heroku. I am trying to connect to my remote MySQL database that is hosted under my Hostwinds plan. When I tried to connect to the DB in my local environment it wor...
I am having some difficulties for the past few days while trying to connect to a remote MYSQL DB from a Heroku hosted Rails App. Locally I am able to connect to the remote database and retrieve/mod...
aws ec2 setup details: ubuntu18.04 ami, mysql8 installed and user created with native password the my sql db instance allows connection from workbench on laptop have a nodejs app hosted on heroku
I created a web app that I was able to successfully deploy to heroku. The site uses a mysql database that I dumped into the project directory for the app. I followed the instructions from this SO p...

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.