title: Heroku error: "connect ECONNREFUSED 127.0.0.1:3306" when trying to deploy Express + React application
body: <p>I was trying to deploy my Express + React application to Heroku. Heroku connected successfully with my Github account, then clicking &quot;Deploy Branch&quot; led to &quot;Your app was successfully deployed&quot;. But when I went to view my website, it showed:</p>
  <p>&quot;Application error An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details&quot;.</p>
  <p>Here are my logs:</p>
  <pre><code>Starting process with command `npm start`
  &gt; myproject@ start /app
  &gt; node backend/index.js
  My project SQL server listening on PORT 4000
  /app/backend/index.js:22
  if (err) throw err;
  ^
  Error: connect ECONNREFUSED 127.0.0.1:3306
  at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
  </code></pre>
  <p>And the <code>index.js</code> which connects to MySQL:</p>
  <pre><code>const express = require('express');
  const cors = require('cors');
  const mysql = require('mysql');
  const app = express();
  
  app.use(cors());
  
  app.get('/', (req, res) =&gt; {
      res.send('go to /my-project to see my project')
  });
  
  const pool = mysql.createPool({
      connectionLimit: 10,
      host: 'localhost',
      user: 'root',
      password: 'myjs123@',
      database: 'my-project',
      debug: false
  });
  
  pool.getConnection((err, connection) =&gt; {
      if (err) throw err;
      app.get('/my-project', (req, res) =&gt; {
          connection.query(SELECT_ALL_FACTS_QUERY, (err, results) =&gt; {
              if (err) {
                  return res.send(err)
              }
              else {
                  return res.json({
                      data: results
                  })
              };
          });
      });
  
  });
  
  const SELECT_ALL_FACTS_QUERY = 'SELECT * FROM `my-project`.`my-table`;';
  
  app.listen(4000, () =&gt; {
      console.log('My project SQL server listening on PORT 4000');
  });
  
  </code></pre>
  <p>What did I do wrong and how could I deploy it?</p>