该请求正在运行,并输出blockInfo,但该范围之外的所有内容均未定义。有人可以帮我将正文保存到可以在其他地方使用的变量中。
const getInfo = () => {
let request = require("request");
let options = {
method: 'GET',
url: 'https://api.eosnewyork.io/v1/chain/get_info',
headers: { accept: 'application/json' }
};
let blockInfo;
request(options, function (error, response, body) {
if (error) throw new Error(error);
blockInfo = JSON.parse(body);
console.log(blockInfo)
return blockInfo
});
console.log(blockInfo)
return blockInfo
}
const blockNum = getInfo()