Created
December 11, 2015 23:56
-
-
Save dawsbot/337292310bc60c74bf4b 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 express = require('express'); | |
var http = require('https'); | |
var app = express(); | |
function getUSD(callback) { | |
http.get('https://blockchain.info/ticker', function(res) { | |
var body = ''; | |
res.setEncoding('utf8'); | |
res.on('data', function(data) { | |
body += data; | |
}); | |
res.on('end', function() { | |
body = JSON.parse(body); | |
callback(body.USD.last); | |
}); | |
}).on('error', function(e) { | |
console.log('Got error: ' + e.message); | |
}); | |
} | |
app.get('/', function (req, res) { | |
getUSD(function(data){ | |
res.send(data.toString()); | |
}); | |
}); | |
var server = app.listen(3000, function () { | |
var host = server.address().address; | |
var port = server.address().port; | |
console.log('Example app listening at http://%s:%s', host, port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment