{"library":"node-bing-api","title":"Node.js Bing Search API Client","description":"The `node-bing-api` library is a Node.js client for integrating with the Microsoft Cognitive Services Bing Web Search API. It provides synchronous and asynchronous access to various Bing search verticals, including Web, Composite, News, Video, Images, Related Search, and Spelling Suggestions. The current stable version is 4.1.1, with its last publication being over five years ago, indicating a maintenance release cadence rather than active feature development. The library is callback-centric by default, requiring the use of `util.promisify` for applications that prefer Promise-based asynchronous operations. A key differentiator is its direct mapping to the Bing API responses, providing raw body data, and its explicit support for features like market specification and adult content filtering. Users must provide a valid Azure Cognitive Services Bing Search API key for functionality.","language":"javascript","status":"maintenance","last_verified":"Wed Apr 22","install":{"commands":["npm install node-bing-api"],"cli":null},"imports":["const BingFactory = require('node-bing-api');\nconst Bing = BingFactory({ accKey: process.env.BING_API_KEY ?? '' });","Bing.web(\"query\", options, callback);","const util = require('util');\nconst searchBingWeb = util.promisify(Bing.web.bind(Bing));"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const util = require('util');\nconst BingFactory = require('node-bing-api');\n\n// Ensure you set your BING_API_KEY as an environment variable\n// You can get one from Azure Cognitive Services\nconst BING_API_KEY = process.env.BING_API_KEY ?? '';\n\nif (!BING_API_KEY) {\n  console.error('Error: BING_API_KEY environment variable is not set.');\n  process.exit(1);\n}\n\nconst Bing = BingFactory({ accKey: BING_API_KEY });\n\n// Option 1: Using callbacks (default)\nBing.web(\"JavaScript library\", {\n    count: 5,\n    offset: 0\n  }, function(error, res, body){\n    if (error) {\n      console.error('Callback Error:', error);\n      return;\n    }\n    if (body && body.webPages && body.webPages.value && body.webPages.value.length > 0) {\n      console.log('--- Callback Results (first 2 web pages) ---');\n      console.log(body.webPages.value[0]?.name + ' - ' + body.webPages.value[0]?.url);\n      console.log(body.webPages.value[1]?.name + ' - ' + body.webPages.value[1]?.url);\n    } else {\n      console.log('No web page results found via callback.');\n    }\n  });\n\n// Option 2: Using Promises with util.promisify\nconst searchBingWebPromise = util.promisify(Bing.web.bind(Bing));\n\nasync function performPromiseSearch() {\n  try {\n    const [res, body] = await searchBingWebPromise(\"TypeScript documentation\", {\n      count: 3,\n      offset: 0\n    });\n\n    if (body && body.webPages && body.webPages.value && body.webPages.value.length > 0) {\n      console.log('\\n--- Promise Results (first web page) ---');\n      console.log(body.webPages.value[0]?.name + ' - ' + body.webPages.value[0]?.url);\n    } else {\n      console.log('No web page results found via Promise.');\n    }\n  } catch (error) {\n    console.error('\\nPromise Error:', error);\n  }\n}\n\nperformPromiseSearch();","lang":"javascript","description":"This quickstart demonstrates how to initialize the `node-bing-api` client, perform a web search using both the default callback-based approach, and how to adapt it for Promise-based usage with `util.promisify` for modern asynchronous patterns. It emphasizes the need for an API key.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}