The following should work:
var request = Promise.promisify(require("request"));
Promise.promisifyAll(request);
Note that this means that request
is not a free function since promisification works with prototype methods since the this
isn’t known in advance. It will only work in newer versions of bluebird. Repeat it when you need to when forking the request object for cookies.
If you’re using Bluebird v3, you’ll want to use the multiArgs
option:
var request = Promise.promisify(require("request"), {multiArgs: true});
Promise.promisifyAll(request, {multiArgs: true})
This is because the callback for request is (err, response, body)
: the default behavior of Bluebird v3 is to only take the first success value argument (i.e. response
) and to ignore the others (i.e. body
).