Skip to content

Instantly share code, notes, and snippets.

@frontweb
Created September 17, 2010 13:40
Show Gist options
  • Save frontweb/584240 to your computer and use it in GitHub Desktop.
Save frontweb/584240 to your computer and use it in GitHub Desktop.
var sys = require('sys'),
http = require('http'),
url = require('url'),
request = require('./vendor/plugins/request/main');
// Connect to DB
var db = require('./vendor/plugins/nodejs-mysql-native/mysql/client').createTCPClient('localhost', 8889);
db.auth('db_name', 'root', 'root');
// Server
http.createServer(function(req, response_to_send) {
// ... validate params ...
request({uri:params.url}, function (error, response, body) { // Fetch webpage
if (!error && response.statusCode == 200) {
// prepare text (body) ...
db.query("SELECT ...").addListener('row', function(keyword) {
// search keyword ...
}).addListener('end', function(){
// output response ...
});
}
});
}).listen(8124);
sys.puts('Server running at http://127.0.0.1:8124');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment