I am a newbie to NODEJS, Java-script programming, so learning the basics
I am planning to host this code in AWS and call it from my computer through the internet connection
var http = require('http');
var mysql = require('mysql');
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
database: 'node'
});
console.log('MySQL Connection details '+connection);
http.createServer(function (request, response)
{
console.log('Creating the http server');
connection.query('SELECT id, content FROM test WHERE id IN (1, 2)', 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));
//response.end();
});
}).listen(8084);
Any links or guidance would help also!!
Thanks !!
Consider using express (http://expressjs.com/). You can find a nice tutorial there : http://coenraets.org/blog/2012/10/creating-a-rest-api-using-node-js-express-and-mongodb/.