Created
September 17, 2010 13:40
-
-
Save frontweb/584240 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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