I have code using node-bing-api . It works erroneously and works fine , but I would like to convert it to using Promises (and await ).
I am using node 8 and util.promisify . In the code below, Bing.web is regular err-first code, and searchBing is a promising version.
var findParentDir = require('find-parent-dir'), configDir = findParentDir.sync(__dirname, 'config.js'), config = require(configDir+'config.js'), util = require('util'), log = console.log.bind(console), Bing = require('node-bing-api')({ accKey: config.cognitiveServices.bingSearch }), searchBing = util.promisify(Bing.web); var start = async function(){
The promised version is not fulfilled:
(node:1752) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: this.searchVertical is not a function
This is a bug inside node -bing-api. But shouldn't util.promisify easily pass parameters to the real Bing.web using the same arguments as the original function?
Why does this function not work if it was promised?
Note. I can create my own propositional version that works, but I do not want to create additional code:
var searchBing = function(){ return new Promise(function(resolve, reject) { Bing.web('windows', {top: 5}, function(err, searchResults){ if ( err ) { reject(err) return } resolve(searchResults) }) }) }
source share