我是NODEJS的新手,Java脚本编程,所以学习基础知识
我打算在AWS中托管此代码,并通过互联网连接从我的计算机上调用
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);
任何链接或指导也会有所帮助!!
谢谢!
答案 0 :(得分:0)
考虑使用express(http://expressjs.com/)。你可以在那里找到一个很好的教程:http://coenraets.org/blog/2012/10/creating-a-rest-api-using-node-js-express-and-mongodb/。