How to get Trending GitHub Repositories Using Node.js ? Last Updated : 13 Aug, 2020 Comments Improve Suggest changes Like Article Like Report Approach: Fetch the entire HTML page and store it as string using request package.Load HTML into cheerio and find the CSS selectors to extract repositories details. Using request package: request package: The request is designed to be the simplest way possible to make http calls. It supports HTTPS and follows redirects by default. Installing request package: $ npm install request Note: Run this command in current folder, where ‘app.js’ file located. Syntax for request: request(url, (error, response, body) => { if(!error && response.statusCode == 200) { statements to be executed. } } Parameters: url: API endpoint to which request is made. response: HTTP response status codes indicate whether a specific HTTP request has been successfully completed. body: Response data. Using cheerio package: cheerio package: Fast, flexible & lean implementation of core jQuery designed specifically for the server. Installing cheerio package: $ npm install cheerio Note: Run this command in current folder, where ‘app.js’ file located. Syntax for cheerio: const cheerio = require('cheerio') const $ = cheerio.load(HTMLString) $(CSS Selector).text('Hello there!') $.html() javascript // Import request package const request = require('request'); // Import cheerio package const cheerio = require('cheerio'); // Github Trending Page URL const url = 'https://github.com/trending'; // Get request to the URL request.get(url, (error, response, body) => { // If the response code is 200 and // there is no error if (!error && response.statusCode == 200) { // Load HTML string into cheerio const $ = cheerio.load(body); // Below are the CSS selectors to // fetch the data required let temp = $('.Box-row') let repos = $('.h3.lh-condensed a'); let data = []; for (let i = 0; i < repos.length; i++) { let reponame = $(temp[i]) .find('.h3.lh-condensed a') .text().replace( /[\n\r]+|[\s]{2, }/g, ' ').trim(); let repolanguage = $(temp[i]) .find( '.f6.text-gray.mt-2 span span[itemprop="programmingLanguage"]') .text() .replace(/[\n\r]+|[\s]{2, }/g, ' ').trim(); let repostars = $(temp[i]) .find( '.f6.text-gray.mt-2 .muted-link.d-inline-block.mr-3') .text() .replace(/[\n\r]+|[\s]{2, }/g, ' ').trim(); // Push the fetched data into an object data.push({ 'Repository': reponame, 'Language': repolanguage, 'Stars/Forks': repostars }) } // Display the Object created using console.table console.table(data) } else { console.log("Unable to fetch data from github"); } }); Output: Comment More infoAdvertise with us Next Article How to get Trending GitHub Repositories Using Node.js ? M manoj_n Follow Improve Article Tags : JavaScript Web Technologies Node.js Node.js-Misc Similar Reads How To Push A Big Next.js App To GitHub? Managing a big Next.js and version control of the deployed Next. js application could be challenging sometimes, especially when it comes to file size and repository issues. This guide will help you no matter if you are an experienced programmer or a person who never used GitHub at all. It explains h 3 min read How to resolve error "npm WARN package.json: No repository field" ? The warning "npm WARN package.json: No repository field" indicates that the package.json file in your project lacks a "repository" field. The "repository" field is crucial for providing information about the version-controlled source code repository of your project. While not mandatory, including th 3 min read How to use Node.js REPL ? Node.Js REPL or Read-Evaluate-Print Loop is an interactive shell for the Node.js environment which means we can write any valid Javascript code in it. This is used to test, evaluate, experiment, or debug code much easier and accessible way. It basically acts as the Browser's Web dev tools' Console f 6 min read How to Push Anything to GitHub using Git Bash? GitHub has become the go-to platform for collaborative software development, offering powerful tools for version control, collaboration, and project management. Git Bash, a command-line interface for Git on Windows, provides a quick way to interact with GitHub repositories. In this guide, we'll lear 3 min read How to Deploy Your React Websites on GitHub? Building a web application is always exciting for developers, especially when you step into the programming world for the first time. You build the front end of your application after a lot of struggle, and you want to showcase your skill, your creativity, and of course, your hard work to the world. 6 min read Like