我正在使用requsts包从另一台服务器调用api。但是函数外部的全局变量没有得到更新并显示未定义。
var request = require('request');
var contractAddress;
var abi;
request('http://expressanthem:9000/getcontractAddress',function(error,response,body){
contractAddress=body;
console.log(contractAddress+" "+"contract address at first");
});
request('http://expressanthem:9000/getcontractAbi',function(error,response,body1){
// contract=body1;
// console.log(typeof contract);
abi=body1;
console.log(abi+" "+"This is the abi at first");
});
console.log("The contractAddress is"+" "+contractAddress);
console.log("The cotractABI is"+" "+abi);
module.exports={
contractAddress,
abi
};
全局变量ABI和合约地址未定义值。