forked from ibakshay/bitcoinRate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (36 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const express = require("express");
const bodyParser = require("body-parser");
const request = require("request");
const app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.listen(3000, function(){
console.log("server is up and running on port 3000");
});
app.get("/", function(req,res){
res.sendfile(__dirname + "/index.html");
});
app.post("/bitcoin", function(req,res){
//console.log(req.body);
var crypto = req.body.crypto;
var fiat = req.body.fiat;
var amt = req.body.amount;
var options = {
url : "https://apiv2.bitcoinaverage.com/convert/global",
method : "GET",
qs: {
from: crypto,
to: fiat,
amount: amt
}
}
//api request
request(options, function(error,response, body){
var data = JSON.parse(body);
var price = data.price;
console.log(price);
var currentDate = data.time;
res.write("the current date is " + currentDate + " and " );
res.write("the price of " + amt + " " + crypto + " is currently worth " + price + fiat );
res.send();
})
});