Skip to content

Instantly share code, notes, and snippets.

@dawsbot
Created December 11, 2015 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dawsbot/337292310bc60c74bf4b to your computer and use it in GitHub Desktop.
Save dawsbot/337292310bc60c74bf4b to your computer and use it in GitHub Desktop.
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