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

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -