Created
January 19, 2016 01:26
-
-
Save pvsousalima/037e3b13b9470c4c5155 to your computer and use it in GitHub Desktop.
node.js getting dollar rate
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
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