app.js
1.18 KB
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
var express = require('express');
var app = express();
var fs = require('fs');
const fetch = require('node-fetch');
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.get('/price', function(req, res) {
var arr ;
var responseList = new Array();
fs.readFile('coin_name.txt', 'utf8', function(err,data){
arr = data.split(",");
console.log(arr);
for(var i=0;i<1;i++){
const url = 'https://api.upbit.com/v1/candles/minutes/1?market='+arr[i]+'&count=1';
const options = {method: 'GET', headers: {Accept: 'application/json'}};
var coinJson = new Object();
fetch(url, options)
.then(req => req.json())
.then(json => {
coinJson.coin = arr[i];
coinJson.price = json[0]["trade_price"];
responseList.push(coinJson);
})
.catch(err => console.error('error:' + err));
}
}).then(function(){
jsonData = JSON.stringify(responseList);
res.send(jsonData);
});
})
var server = app.listen(8082);
console.log("Server Created..");