var cluster = require('cluster');  
var os = require('os');

var numCPUs = os.cpus().length;
var express   =    require("express");
var mysql     =    require('mysql');



var app       =    express();

var pool      =    mysql.createPool({
	connectionLimit : 100, //important
	host     : process.env.DBURL,
	user     : process.env.DBUSER,
	password : process.env.DBPW,
	database : 'blah',
	debug    :  false
});

function handle_database(req,res) {

	pool.getConnection(function(err,connection){
		if (err) {
		  connection.release();
		  res.json({"code" : 100, "status" : "Error in connection database"});
		  return;
		}   

	
		connection.query("select * from user order by age",function(err,rows){
			connection.release();
			if(!err) {
				res.json(rows);
			}           
		});

		connection.on('error', function(err) {      
			  res.json({"code" : 100, "status" : "Error in connection database"});
			  return;     
		});
  });
}

app.get("/",function(req,res){
	handle_database(req,res);
});

if (cluster.isMaster) {  
  // Master:
  // Let's fork as many workers as you have CPU cores
  for (var i = 0; i < numCPUs; ++i) {
    cluster.fork();
  }
  
} else {

	

	app.listen(3001);

}

@@ -192,24 +192,560 @@
 express();%0A%0A
+var connection = mysql.createConnection(%7B%0A  host     : process.env.DBURL,%0A  user     : process.env.DBUSER,%0A  password : process.env.DBPW,%0A  database : 'blah'%0A%7D);%0A%0A%0Aconnection.connect(function(err)%7B%0Aif(!err) %7B%0A%7D else %7B%0A    console.log(%22Error connecting database ... %5Cn%5Cn%22);  %0A%7D%0A%7D);%0A%0Aapp.get(%22/%22,function(req,res)%7B%0Aconnection.query('SELECT * from user LIMIT 2', function(err, rows, fields) %7B%0Aconnection.end();%0A  if (!err)%0A    res.json(rows);%0A  else%0A    console.log('Error while performing Query.');%0A  %7D);%0A%7D);%0A%0A// app.listen(3000);%0A// %0A// 
 var pool    
@@ -770,16 +770,19 @@
 ePool(%7B%0A
+// 
 %09connect
@@ -809,16 +809,19 @@
 portant%0A
+// 
 %09host   
@@ -843,16 +843,19 @@
 .DBURL,%0A
+// 
 %09user   
@@ -878,16 +878,19 @@
 DBUSER,%0A
+// 
 %09passwor
@@ -911,16 +911,19 @@
 v.DBPW,%0A
+// 
 %09databas
@@ -934,16 +934,19 @@
 'blah',%0A
+// 
 %09debug  
@@ -956,21 +956,30 @@
   false%0A
+// 
 %7D);%0A
-%0A
+// %0A// 
 function
@@ -1006,17 +1006,23 @@
 ,res) %7B%0A
-%0A
+// %0A// 
 %09pool.ge
@@ -1059,16 +1059,19 @@
 ction)%7B%0A
+// 
 %09%09if (er
@@ -1075,16 +1075,19 @@
 (err) %7B%0A
+// 
 %09%09  conn
@@ -1104,16 +1104,19 @@
 ease();%0A
+// 
 %09%09  res.
@@ -1180,16 +1180,19 @@
 ase%22%7D);%0A
+// 
 %09%09  retu
@@ -1199,18 +1199,30 @@
 rn;%0A
+// 
 %09%09%7D   %0A
-%0A%09%0A
+// %0A// %09%0A// 
 %09%09co
@@ -1290,16 +1290,19 @@
 ,rows)%7B%0A
+// 
 %09%09%09conne
@@ -1318,16 +1318,19 @@
 ease();%0A
+// 
 %09%09%09if(!e
@@ -1335,16 +1335,19 @@
 !err) %7B%0A
+// 
 %09%09%09%09res.
@@ -1358,16 +1358,19 @@
 (rows);%0A
+// 
 %09%09%09%7D    
@@ -1381,15 +1381,24 @@
    %0A
+// 
 %09%09%7D);%0A
-%0A
+// %0A// 
 %09%09co
@@ -1440,16 +1440,19 @@
 %7B      %0A
+// 
 %09%09%09  res
@@ -1517,16 +1517,19 @@
 ase%22%7D);%0A
+// 
 %09%09%09  ret
@@ -1542,23 +1542,38 @@
    %0A
+// 
 %09%09%7D);%0A
+//
   
+ 
 %7D);%0A
-%7D%0A%0A
+// %7D%0A// %0A// 
 app.
@@ -1599,16 +1599,19 @@
 q,res)%7B%0A
+// 
 %09handle_
@@ -1629,19 +1629,26 @@
 q,res);%0A
-%7D);
+// %7D);%0A// 
 %0A%0Aif (cl
@@ -1828,12 +1828,12 @@
 ten(
-3001
+8080
 );%0A%0A

remove pool