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.
npm install node-bing-apiVerified import paths — ran on the pinned version, not inferred.
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.
Review the official Microsoft Bing Search API v7 documentation for any changes in request parameters or response structures. Update your API key if necessary, and carefully test existing integrations.
Ensure your Bing API key is provisioned for Cognitive Services and review the API documentation for any breaking changes between the legacy Bing Search API and Cognitive Services endpoints.
Update all `Bing` method calls (e.g., `Bing.web`, `Bing.images`) to ensure the callback function is the absolute last argument. For example, `Bing.web("query", { options }, callback);`.For Promise usage, always use `const promisedMethod = util.promisify(Bing.originalMethod.bind(Bing));` and `await promisedMethod(...);`. Do not directly call `.then()` on callback-based methods.
Obtain an API key from the Azure portal for Bing Search API. Ensure it's correctly passed during `node-bing-api` initialization via the `accKey` option.
Consult the Bing API documentation for specific `count` and `offset` limits for each search vertical (Web, News, Images, etc.) and adjust your query parameters accordingly.
Verify that your `accKey` is correct and active. Add robust error handling to check the `error` parameter in the callback and inspect `res.statusCode` before attempting to access properties on `body`.
Ensure the initialization is `const Bing = require('node-bing-api')({ accKey: 'your-account-key' });`. Do not omit the `({ accKey: '...' })` part.You must use `util.promisify(Bing.web.bind(Bing))` to create a Promise-returning version of the method. Ensure you include `.bind(Bing)` to maintain the correct context.
Double-check your `accKey` for typos. Ensure your Azure subscription is active and the Bing Search API resource is properly configured and enabled.
No dependency data recorded yet.