necroface necroface - 1 year ago 168
Javascript Question

Promise.promisify is not a function

I wrote JavaScript like this:

var keys=null;
var promise=Promise.promisify(alchemyapi.keywords("url",myUrl,{},function(response) {
var keywords = { url:myUrl, response:JSON.stringify(response,null,4), results:response['keywords'] };
return keywords;
var keys=result;

I'm using AlchemyAPI and trying to store data I got into my database
How should I do?

Answer Source

You should be able to use Promise to return expected results by removing .promisify which is not a built-in Promise method ; substituting passing keywords to resolve within Promise constructor for return

var keys = null
, promise = new Promise(function(resolve) {
    alchemyapi.keywords("url", myUrl, {}, function(response) {
      var keywords = {url: myUrl
                      , response: JSON.stringify(response,null,4)
                      , results:response['keywords'] 
      // error handling ?
  }).then(function(result) {
      keys = result;
  }, function(err) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download