title: Sending data from js to html with ejs components
body: <p>I've just begun to learn about JS and node.js. I've been trying to do some practicing on sending data from a DB in MySQL to the html via ejs components. I tried using ejs.render(data, {data: something_from_DB}); to send fetched information(something_from_DB), identified by "data". I then used the identifier "data" in the ejs code in html, but it'd complain that data is not defined in the html file.</p>
  
  <p>Here's the js code.</p>
  
  <pre><code>var mysql = require('mysql');
  var fs = require('fs');
  var http = require('http');
  var express = require('express');
  var ejs = require('ejs');
  var app = express();
  app.use(app.router);
  
  var client = mysql.createConnection({
      user: 'username',
      password: 'password',
      database: 'database_name'
  });
  
  app.get('/', function(req, res){
  
      fs.readFile('list.html', 'utf8', function(error, data){
          client.query('SELECT * FROM test_table', function(error, results){
              console.log(results);
              res.send(ejs.render(data), {data: results});
          });
      });
  });
  </code></pre>
  
  <p>And here's the portion from list.html</p>
  
  <pre><code>&lt;% data.forEach(function(item, index){ %&gt;
  &lt;tr&gt;
      &lt;td&gt;&lt;%= item.id %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= item.name %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= item.phone_no %&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;% }); %&gt;
  </code></pre>
  
  <p>When I print the results, I get: </p>
  
  <pre><code>[ RowDataPacket { id: 1, name: 'PETER', phone_no: '0100000000' } ]
  </code></pre>
  
  <p>which looks fine. I'm looking to pass this with "data" but I don't think this is happening. </p>
  
  <p>Please do correct me if I'm using words that are out of context.</p>