title: JSON response using express
body: <h2>I have a working code from Express that returns JSON response from the server to client</h2>
  
  <p>Here </p>
  
  <ul>
  <li>when i use <code>http:://myserverip/</code> I get a JSON from Table1</li>
  <li>when i use <code>Http:://myserverip/table2</code> I get a JSON from Table2</li>
  </ul>
  
  <p><em><strong>So as i understand i need to make 2 separate requests to get JSON from two separate tables
  But is there a way to get data from both the tables at a time in one JSON response</em></strong></p>
  
  <pre><code>var express = require('express')
    , http = require('http')
    , mysql = require('mysql'); // &lt;---- HERE
  
  var app = express();
  
  var connection = mysql.createConnection({
      host: 'localhost',
      user: 'root',
      password: "root",
      database: 'DB'
  });
  
  connection.connect(); // &lt;---- AND HERE
  
  // all environments
  app.set('port', process.env.PORT || 7002);
  
  
  app.get('/',function(request,response){
  connection.query('SELECT * FROM table1', function(err, rows, fields)
  
      {
              console.log('Connection result error '+err);
              console.log('no of records is '+rows.length);
                      response.writeHead(200, { 'Content-Type': 'application/json'});
              response.end(JSON.stringify(rows));
      });
  
  } );
  
  
  app.get('/table2',function(request,response){
  connection.query('SELECT * FROM table2', function(err, rows, fields)
  
      {
              console.log('Connection result error '+err);
              console.log('no of records is '+rows.length);
                      response.writeHead(200, { 'Content-Type': 'application/json'});
              response.end(JSON.stringify(rows));
      });
  
  } );
  
  
  
  http.createServer(app).listen(app.get('port'), function(){
    console.log('Express server listening on port ' + app.get('port'));
  });
  </code></pre>
  
  <p><strong>Thanks</strong></p>