-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (32 loc) · 1.05 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
44
45
46
47
48
49
const express = require("express");
const bodyParser = require("body-parser");
const request = require("request");
const app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.get("/", function(req,res){
res.sendFile(__dirname + "/index.html");
});
app.post("/", function(req,res){
var crypto = req.body.crypto;
var fiat = req.body.fiat;
var amount = req.body.amount;
var options = {
url: "https://apiv2.bitcoinaverage.com/convert/global",
method: "GET",
qs: {
from: crypto,
to: fiat,
amount: amount
}
}
request(options, function(error, response, body){
var data = JSON.parse(body);
var price = data.price;
res.write("Date and time : "+ data.time);
res.write("<h1>The price of the "+crypto+ " is " +price+ fiat +"</h1>");
res.send();
});
});
app.listen(3000, function(){
console.log("i am port 3000 i am ready to go...");
});