title: MEAN Stack Node Js with SQL Database - fetch Datatable and read it on the browser local host
body: <p>I am building an App with MEAN Stack and would like to integrate a SQL database, in particular fetching datatables and reading them on the browser local host.</p>
  
  <p>So far, Im able to read any datatable with the following code. However, this code just console logs the data tables in the terminal, but I would like to read them in  the browser. Any suggestions?</p>
  
  <pre><code>var Connection = require("tedious").Connection;
  var Request = require("tedious").Request;
  
  // Create connection to database
  var config = {
    userName: "insert username",
    password: "insert password",
    server: "insert server",
    options: {
      database: "insert database name",
      encrypt: true
    }
  };
  var connection = new Connection(config);
  
  // Attempt to connect and execute queries if connection goes through
  connection.on("connect", function(err) {
    if (err) {
      console.log(err);
    } else {
      console.log("Connected to SQL database!");
      queryDatabase();
    }
  });
  
  function queryDatabase() {
    console.log("Reading rows from the Table...");
  
    // Read all rows from table
    request = new Request("SELECT * from &lt;insert name of existing datatable from database", function(
      err,
      rowCount,
      rows
    ) {
      console.log(rowCount + " row(s) returned");
      process.exit();
    });
  
    request.on("row", function(columns) {
      columns.forEach(function(column) {
        console.log("%s\t%s", column.metadata.colName, column.value);
      });
    });
    connection.execSql(request);
  }
  </code></pre>