How to have SQL query results returned and stored in localhost window variable, rather than the terminal, using Node.js?

I'm fairly new to Web Development and this is my first attempt at querying a DB and actually doing something with the data returned.

I'm using Node.js to query a Database

I have the following app.js file :

var querySomeDatabase = function (someSqlQuery)
{
  var mysql      = require('mysql');

  var connection = mysql.createConnection(
  {
    host     : 'xxxxxxx.com',
    user     : 'readonly',
    password : 'xxxxxxxxxxxxxxx',
    database : 'xxxxxxxxxxxxx'
  });

  connection.connect();

  connection.query(someSqlQuery, function (err, rows, fields)
  {
    if (err)
    {
      throw(err);
    }
    else
    {
      return rows;
    }
  });

  connection.end();
};

Currently, I execute node app.js on my Mac's terminal and I get an array of objects in the terminal, containing the results of my query.

What do I need to do so that I can open up a localhost window and have the results stored in a window variable so that I can use them client-side (sort of an exercise so that I can train myself on how to use the data returned to build an html document..) ?

Node (and all servers) work based on client requests and server responses. When the client makes a request for certain information, the server detects the request, (in this case runs the query), and then serves the response. If you want the client to get records in javascript, you have to serve a JSON representation back to the client.

A great tool for making requests and responses simpler is Express.js

Let me know if you want some code samples.