错误 myFunction(...).then 不是函数

Error myFunction(...).then is not a function

我有以下模块,基本上执行对 Google 的 GET 请求:

// my-module.js
var request = require('request');
var BPromise = require('bluebird');

module.exports = get;

function get() {
    return BPromise.promisify(doRequest);
}

function doRequest(callback) {
    request.get({
        uri: "http://google.com",
    }, function (err, res, body) {
        if (!err && res.statusCode == 200) {
            callback(null, body);
        }
        else {
            callback(err, null);
        }
    });
}

我想像这样使用这个模块:

//use-module.js
var myModule = require('./my-module');

myModule().then(function (body) {
     console.log(body);
});

我遇到的错误如下:

myModule(...).then is not a function.

我做错了什么?

BPromise.promisify(doRequest) 不调用 doRequest,但 returns 是该函数的 "promisified" 版本。你应该这样做一次,而不是在每次通话时。这应该有效:

module.exports = BPromise.promisify(doRequest);