×

Node.js client library

Use Node.js client library to integrate News API into your Node.js application

const u = require("unirest"); //intsall from: http://unirest.io/nodejs.html

//Replace the following string value with your valid X-RapidAPI-Key.

Your_X_RapidAPI_Key = "XXXXXXXXXXXXXXXXXXXX";

//The query parameters: (update according to your search query)
q = "Taylor%20Swift"; #the search query
pageNumber = 1; #the number of requested page
searchEngineId = "XXXX"; #the id of the custom search engine 

u.get("https://custom-search.p.rapidapi.com/api/search/CustomImageSearchAPIV2?q=" + q + "&pageNumber=" + pageNumber + "&searchEngineId=" + searchEngineId)
    .header("X-RapidAPI-Key", Your_X_RapidAPI_Key)
    .end(function(result) {

        console.log("HTTP status code: " + result.status);

        //Get the numer of items returned
        totalCount = result.body["totalCount"];

        for (i = 0; i < result.body["value"].length; i++) {

            image = result.body["value"][i];

            //Get the image
            imageUrl = image["url"];
            imageHeight = image["height"];
            imageWidth = image["width"];

            //Get the image thumbail
            thumbnail = image["thumbnail"];
            thumbnailHeight = image["thumbnailHeight"];
            thumbnailWidth = image["thumbnailWidth"];

            //An example: Output the webpage url, title and published date:
            console.log("imageUrl: %s. imageHeight: %s. imageWidth: %s.n", imageUrl, imageHeight, imageWidth);
        }

    });