Skip to content

Instantly share code, notes, and snippets.

@pvsousalima
Created January 19, 2016 01:26
Show Gist options
  • Save pvsousalima/037e3b13b9470c4c5155 to your computer and use it in GitHub Desktop.
Save pvsousalima/037e3b13b9470c4c5155 to your computer and use it in GitHub Desktop.
node.js getting dollar rate
app.get('/dollarRate', function(request, response) {
var from = "USD"
var to = "BRL"
var url = "http://query.yahooapis.com/v1/public/yql?q=select%20rate%2Cname%20from%20csv%20where%20url%3D'http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes%3Fs%3DUSDBRL%253DX%26f%3Dl1n'%20and%20columns%3D'rate%2Cname'&format=json"
http.get(url, function(res){
var body = '';
res.on('data', function(chunk){
body += chunk;
});
res.on('end', function(){
var fbResponse = JSON.parse(body);
var rate = fbResponse.query.results.row.rate
//console.log("Got a response: ", fbResponse.query.results.row.rate);
response.send(rate)
});
}).on('error', function(e){
console.log("Got an error: ", e);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment