Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var http = require('http');
- var express = require('express');
- var numeral = require('numeral');
- var moment = require('moment');
- var open = require('open')
- var app = express();
- var port = 3000;
- app.listen(port, function(err){
- open('http://localhost:' + port);
- });
- app.get('/', function(req, rep){
- rep.write('Everything is good');
- rep.end();
- });
- app.get('/btc', function(req, resp){
- resp.write('Todays price...')
- btc(function(data){
- resp.write('Price: ' + data.price + '\r');
- resp.write('Date: ' + data.timeStamp);
- resp.end();
- });
- });
- function btc(callback){
- var options = {
- hostname: 'winkdex.com',
- path: '/api/v0/price',
- method: 'GET',
- port: 80,
- headers: {}
- };
- http.request(options, function(resp){
- var data = '';
- var btc = {};
- resp.on('data', function(chunk){
- data += chunk
- });
- resp.on('end', function(){
- var result = JSON.parse(data);
- btc.price = numeral(result.price / 100).format('$0.00');
- btc.timeStamp = moment(result.timestamp).format('DD/MM/YYYY');
- callback(btc);
- });
- }).on('error', function(err){
- console.log(err);
- }).end();
- }
Advertisement
Add Comment
Please, Sign In to add comment