title: Connect MySQL database with node JavaScript application
body: <p>I make a node JavaScript app and deploy it on cPanel using SSH.
  App is working fine without database but when I connect the app with database on cPanel (GoDaddy) it takes times and shows the message "Error establishing a database connection".
  My connection code</p>
  
  <pre><code>const mysql = require('mysql');
  const express = require('express');
  const app = express();
  
  var pool = mysql.createConnection({
      host: 'localhost',
      user: '&lt;MY_USER_NAME&gt;',
      password: '&lt;MY_PASSWORD&gt;',
      database: '&lt;DB_NAME&gt;'
  });
  
  pool.connect(function(err) {
    if (err) throw err;
    else{
    console.log("Connected!");
    }
  });
  
  
  
  module.exports = pool;
  </code></pre>
  
  <p>route where DB interact,but lost the connection.</p>
  
  <pre><code>app.post('/loginn', (req, res) =&gt; {
  var id = req.body.id
    console.log("user_id= "+id);
    var sql = "select * from users where id  NOT IN ('" + id + "') ";
      pool.query(sql, function (err, rows) {
          if (err) throw err;
          else {
            res.render('allusers', {
              users: rows,
              user_id:id
            })
          }
      });
    });
  </code></pre>