WebSearchClient Library with typescript type definitions for node

Downloads in past


2.0.05 years ago6 years agoMinified + gzip package size for azure-cognitiveservices-websearch in KB


Microsoft Azure SDK for Node.js - Cognitive Services Web Search
This project provides a Node.js package that makes it easy to work with Microsoft Azure Cognitive Services Web Search API. Right now it supports:
  • Node.js version: 6.x or higher

How to Install

npm install azure-cognitiveservices-websearch

How to use

Create a Cognitive Services Bing Search Account

const msRestAzure = require('ms-rest-azure');
const CognitiveServicesManagement = require("azure-arm-cognitiveservices");
let client;
let createAccount = msRestAzure.interactiveLogin().then((credentials) => {
  client = new CognitiveServicesManagement(credentials, suite.subscriptionId);
  return client.accounts.create('groupname', 'accountname', {
    sku: {
      name: "S1"
    kind: "Bing.Search",
    location: "westus",
    properties: {}
}).catch((err) => {
  console.log('An error ocurred');
  console.dir(err, {depth: null, colors: true});

List the keys from the created account

let serviceKey;
createAccount.then((result) => {
  return client.accounts.listKeys('groupname', 'accountname');
}).then((result) => {
  serviceKey = result.key1;
}).catch((err) => {
  console.log('An error ocurred');
  console.dir(err, {depth: null, colors: true});

Create credentials

```javascript const CognitiveServicesCredentials = require('ms-rest-azure').CognitiveServicesCredentials; let credentials = new CognitiveServicesCredentials(serviceKey); ```

Query the Web Search API

```javascript const WebSearchAPIClient = require('azure-cognitiveservices-websearch'); let webSearchApiClient = new WebSearchAPIClient(credentials);'seahawks').then((result) => { console.log(result.queryContext); let properties = "images", "webPages", "news"; for (let i = 0; i < properties.length; i++){
if (result[properties[i]]){
} else {
  console.log(`No ${properties[i]} data`);
} }).catch((err) => { throw err; }) ```

More Detailed Information under "Search"

Related Projects