I have a working code from Express that returns JSON response from the server to client
Here
- when i use http:://myserverip/I get a JSON from Table1
- when i use Http:://myserverip/table2I get a JSON from Table2
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
var express = require('express')
  , http = require('http')
  , mysql = require('mysql'); // <---- HERE
var app = express();
var connection = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: "root",
    database: 'DB'
});
connection.connect(); // <---- 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'));
});
Thanks