title: Extract data from MySQL using Node.js and display on HTML page
body: <p>I am trying to extract data from MySQL and display it on my HTML page, but when I run the code below on my browser <code>http://localhost:3000</code>, the data does not display on my page. I would appreciate if somebody could help me solve this problem.</p>
  
  <p><strong>index.html</strong></p>
  
  <pre><code>&lt;!DOCTYPE&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Data from MySQL&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div id="output_message"&gt;&lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>app.js</strong></p>
  
  <pre><code>var express = require('express');
  var app = express();
  var mysql = require('mysql');
  var bodyParser = require('body-parser');
  var urlencodedParser = bodyParser.urlencoded({ extended: false });
  
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({extended: false}));
  app.use('/', express.static(__dirname + '/'));
  app.set('view engine', 'html');
  
  var connection = mysql.createConnection({
      host: "localhost",
      user: "root",
      password: "",
      database: "mywebsite"
  });
  
  connection.connect();
  
  app.get('/',(req, res) =&gt; {
      connection.query("SELECT * FROM chat",(err, result) =&gt; {
          if(err) {
              console.log(err); 
              res.json({"error":true});
          }
          else { 
              console.log(result); 
              res.json(result); 
          }
      });
  });
  
  app.listen(3000, function () {
      console.log('Connected to port 3000');
  });
  </code></pre>