Просто нашел ответ сам. Поэтому я пишу это здесь, чтобы это могло быть полезно для кого-то другого. ^\s*\S*\s*$
функция, которая, поскольку ей предшествует
blockquote>async
, возвращает обещаниеПохоже, вы уже почти ответили на свой вопрос. Вам придется подождать это обещание на сайте вызова:
usdToEos().then(usdToEosMul => { console.log('\n' + 'USD multiplier to convert to EOS' + '\n') console.log(usdToEosMul) }).catch(error => { console.log('\nCaught exception: ' + error) }) function usdToEos() { const options = { method: 'GET' ,uri: 'https://api.coincap.io/v2/assets/eos' ,json: true } return request(options).then(response => { console.log(response) return (1 / response.data.priceUsd) }) }
или
;(async function() { try { const usdToEosMul = await usdToEos() console.log('\n' + 'USD multiplier to convert to EOS' + '\n') console.log(usdToEosMul) } catch(error) { console.log('\nCaught exception: ' + error) } }()) async function usdToEos() { const options = { method: 'GET' ,uri: 'https://api.coincap.io/v2/assets/eos' ,json: true } const response = await request(options) console.log(response) return (1 / response.data.priceUsd) }