-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (33 loc) · 1.09 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
const express = require('express');
const bodyParser = require('body-parser');
const request = require('request');
const app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.get("/", (req, res) => {
res.sendFile(__dirname + "/index.html");
});
app.post("/", (req, res) => {
//console.log(req.body.crypto + "/" + req.body.fiat);
let crypto = req.body.crypto;
let fiat = req.body.fiat;
let amount = req.body.amount;
//Request module function
let options = {
url: "https://apiv2.bitcoinaverage.com/convert/global",
method: "GET",
qs: {
from: crypto,
to: fiat,
amount: amount
}
}
request(options, (error, response, body) => {
let data = JSON.parse(body);
let price = data.price;
let currentDate = data.time;
res.write(`<p>As of ${currentDate}</p>`);
res.write(`<h1>The price of ${amount} ${crypto} in ${fiat} is currently ${price}</h1>`);
res.send();
});
})
app.listen(3000, () => console.log("Server running at port 3000"));