I deployed a node app on Heroku and set up ClearDB with MySQL Workbench. When I use npm run start
it works great, data shows up. When I open in Heroku; heroku local web
and heroku open
the app is deployed but no data is displayed. The error message is resource: net::ERR_CONNECTION_REFUSED.
My database is tiny, so the size limit is not an issue. My Procfile
is set to
web: npm run start
Why isn't my clearDB connecting through Heroku?
Some other answers I've read involve an .env
file, which I didn't have. I tried creating one with the DATABASE_URL
but no change. I also tried adding port: process.env.PORT || 3036
to my database config file.
I can connect to the Heroku / ClearDB database through MySQL Workbench and all the tables are there.
My database config file:
import mysql from 'mysql'
let pool = mysql.createPool({
connectionLimit: 10,
user: '******',
password: '*******',
host: '*******',
database: '*******',
port: process.env.PORT || 3036
});
let chirprdb = {};
chirprdb.all = () => {
return new Promise((resolve, reject) => {
pool.query('SELECT * FROM chirps', (err, results) => {
if (err) {
return reject(err);
}
return resolve(results);
})
})
}
export default chirprdb;
Expected result: see the app and all its data on the deployed Heroku URL
Actual result: seeing the app but no data is loading, error is resource: net::ERR_CONNECTION_REFUSED
Edit
I changed the database (so as to not publish my credentials here) and created a new connection with MySQL Workbench. Clicking 'test connection' gave me this warning .
router that imports chirperdb
import { Router } from 'express';
import db from '../db'
let router = Router();
router.get('/:id?', async (req, res) => {
let id = req.params.id;
if (id) {
try {
let results = await db.one(id);
res.json(results);
} catch (e) {
console.log(e);
res.sendStatus(500);
}
} else {
try {
let results = await db.all();
res.json(results);
} catch (e) {
console.log(e);
res.sendStatus(500);
}
}
});