Search code examples
node.jsamazon-web-servicesaws-lambdahttp-getbing-api

HTTPS Get gives connection refused error while connecting to Bing API using nodejs


I was able to connect to the Bing API end point using Chrome extension - Postman.
I am new to NodeJS and AWS Lambda. Seeing the below error while connecting from an AWS Lambda function with nodejs 6.9.0

Error: connect ECONNREFUSED 127.0.0.1:443
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)

Code:

exports.handler = (event, context, callback) => {
var headers = {
'Ocp-Apim-Subscription-Key': '******************',
'Content-Type': 'application/json',
};
var options = {
url: 'https://api.cognitive.microsoft.com/bing/v5.0/search?                
&q=hello',
method: 'GET',
headers: headers,
};
const https = require("https");
https.get(options);
};

Appreciate your help


Solution

  • You may require and use the package node-bing-api to search with Bing Api.

    var Bing = require('node-bing-api')({ accKey: "your-account-key" });
    
    Bing.web("hello", function(error, res, body){
       console.log(body);
     });