【发布时间】:2018-09-18 17:52:10
【问题描述】:
我想在 Node.js 中对另一个文件使用 unirest 请求的结果,但我无法从 request.end() 函数获取数据到外部变量。
代码如下:
request.end(function (response) {
if(response.error) {
console.log("AUTHENTICATION ERROR: ", response.error);
} else {
callback(null, response.body);
}
console.log("AUTHENTICATION BODY: ", response.body);
});
var result = authentication(function(error, response) {
var authenticationToken = response.access_token;
if(authenticationToken != null) {
console.log("Token: ", authenticationToken);
return authenticationToken;
}
});
我想获取 authenticationToken 值以使用 module.exports 导出其他模块。
我正在使用 unirest http 库。
【问题讨论】:
标签: javascript node.js http httprequest unirest