npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-bing-api

v4.1.1

Published

Node.js module for the Cognitive Services Bing Search API

Downloads

1,908

Readme

NPM downloads per month NPM version NPM license

Node Bing API

Node.js lib for the Microsoft Cognitive Services Bing Web Search API

Changelog v4

Use Cognitive V7. Apparently new registrations can use that version only. Upgrade with care!

Changelog v3

Thanks to the contribution of @franciscofsales, version 3 supports the new API (Cognitive Services).

Changelog v2

In order to follow JavaScript best practices and allow the library to be promisified, the callback function is now the last parameter.

Installation

npm install node-bing-api

Usage

Require the library and initialize it with your account key:

var Bing = require('node-bing-api')({ accKey: "your-account-key" });

Promises

This API provdes callbacks by default, but users of node 8 and newer can make the library return Promises with util.promisify(). For example, to use Bing.web:

var util = require('util'),
  Bing = require('node-bing-api')({ accKey: 'someKey' }),
  searchBing = util.promisify(Bing.web.bind(Bing));

Web Search (same as Composite):

Bing.web("Pizza", {
    count: 10,  // Number of results (max 50)
    offset: 3   // Skip first 3 results
  }, function(error, res, body){

    // body has more useful information besides web pages
    // (image search, related search, news, videos)
    // but for this example we are just
    // printing the first two web page results
    console.log(body.webPages.value[0]);
    console.log(body.webPages.value[1]);
  });

Composite Search (same as Web):

Bing.composite("Playstation 4 Pro", {
    count: 10,  // Number of results (max 15 for news, max 50 if other)
    offset: 3   // Skip first 3 results
  }, function(error, res, body){
    console.log(body.news);
  });

News Search:

Bing.news("Anonymous", {
    count: 10,  // Number of results (max 15)
    offset: 3   // Skip first 3 results
  }, function(error, res, body){
    console.log(body);
  });

Video Search:

Bing.video("monkey vs frog", {
    count: 10,  // Number of results (max 50)
    offset: 3   // Skip first 3 result
  }, function(error, res, body){
    console.log(body);
  });

Images Search:

Bing.images("Ninja Turtles", {
  count: 15,   // Number of results (max 50)
  offset: 3    // Skip first 3 result
  }, function(error, res, body){
    console.log(body);
  });

Related Search (same as Web):

Bing.relatedSearch('berlin'
, { market: 'en-US' }
, (err, res, body) => {
    const suggestions = body.relatedSearches.value.map(r => r.displayText)
    console.log(suggestions.join('\n'))
  })

Spelling Suggestions:

Bing.spelling('awsome spell', function (err, res, body) {
  console.log(body.flaggedTokens.suggestions[0].suggestion); //awesome spell
});

Requires specific Account key

Available Options:

  • mode:<Proof | Spell>
  • preContextText:<String>
  • postContextText:<String>

request() options

  • maxSockets: integer (default: Infinity)
  • reqTimeout: ms

Specify Market

Getting spanish results:

Bing.images("Ninja Turtles"
          , {count: 5, market: 'es-ES'}
          , function(error, res, body){

  console.log(body);
});

Full list of supported markets: es-AR,en-AU,de-AT,nl-BE,fr-BE,pt-BR,en-CA,fr-CA,es-CL,da-DK,fi-FI,fr-FR, de-DE,zh-HK,en-IN,en-ID,en-IE,it-IT,ja-JP,ko-KR,en-MY,es-MX,nl-NL,en-NZ, no-NO,zh-CN,pl-PL,pt-PT,en-PH,ru-RU,ar-SA,en-ZA,es-ES,sv-SE,fr-CH,de-CH, zh-TW,tr-TR,en-GB,en-US,es-US

Adult Filter

Bing.images('Kim Kardashian'
          , {market: 'en-US', adult: 'Strict'}
          , function(error, res, body){

  console.log(body.value);
});

Accepted values: "Off", "Moderate", "Strict".

Moderate level should not include results with sexually explicit images or videos, but may include sexually explicit text.

Web Only API Subscriptions

To use this library with a web only subscription, you can require and initialize it with an alternate root url:

var Bing = require('node-bing-api')
            ({
              accKey: "your-account-key",
              rootUri: "https://api.datamarket.azure.com/Bing/SearchWeb/v1/"
            });

Running Tests

In order to run the tests, the integration tests require to create a secrets.js file from the provided secrets.js.example example, and fill it in with a valid access key.

Then just mocha.

License

MIT