test.js 993 Bytes
const fetch = require('node-fetch');
var fs = require('fs');

var responseList = new Array();
fs.readFile('coin_name.txt', 'utf8', function(err,data){
    arr = data.split(",");
    
   // console.log(arr);
    
    for(var i=0;i<10;i++){
        (function(i){
            setTimeout(function(){
                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(res => res.json())
            .then(json => {
                coinJson.coin = arr[i];
                coinJson.price = json[0].trade_price;
            })
            .then(function(){
                responseList.push(coinJson);
                console.log(responseList);
                
            })
            .catch(err => console.error('error:' + err));
            },10);
        })(i);
        
    }
    
})