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


i have following module performs request google:

// 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);         }     }); } 

and want use module so:

//use-module.js var mymodule = require('./my-module');  mymodule().then(function (body) {      console.log(body); }); 

the error i'm facing following:

mymodule(...).then not function.

what doing wrong?

bpromise.promisify(dorequest) not call dorequest, returns "promisified" version of function. should once, not @ each call. should work:

module.exports = bpromise.promisify(dorequest); 

Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -