how to generate JSON for an simple SQL query with NODEJS

What changes should i need to make to run this simple program

  • I have created a local database
  • My database name is node
  • my table name is text
  • I have just two fields in the table test
  • there is no password for the database
  • I am able to execute this .js file in node server and run on the browser but i am not able to generate JSON on browser

var http = require('http')
var mysql = require('mysql');
var client = mysql.createConnection({
host: 'localhost',
user: 'root'
});

client.query('USE node');

http.createServer(function (request, response) 
{

   request.on('end', function () 
   {

      connection.query('SELECT id, content FROM test WHERE id IN (?, ?)',[1, 2], function(err, results, fields)
      {

         response.end(JSON.stringify(results));
      });
   });
}).listen(8080);

Thanks