我正在試圖讓調用API模塊,使用下面的代碼裏面返回的數據:的NodeJS模塊無法從封閉
var key = require('./keys').slack;
var unirest = require('unirest');
module.exports.apiCall = function() {
var args = {"token": key, "channel": "C07RLKT6C", "text": "DebugmessagePlsIgnore", "as_user": true};
var req = unirest.post("https://slack.com/api/chat.postMessage");
req.query(args).end(function(res) {
// Output res
});
}
console.log(this.apiCall());
不幸的是,我無法輸出資源的到結果返回。我正在使用Unirest模塊來請求HTTPS數據。
謝謝。
你不能那樣做。 http://blog.slaks.net/2015-01-04/async-method-patterns/ – SLaks
@SLaks對不起,但我不明白這個鏈接。 – Justin