Speed up development with full-stack environments for every branch.

Learn More

Search popular repositories on GitHub [Node.js]

Forked from Hello World for Node.js.

271 Runs 854 Views 117 Copies

Uses the GitHub v3 API to gather the most starred public repositories on GitHub

Saved

Saved

sundip 66

sundip
published 4 years ago

var express = require('express')
  , request = require('request')
  , qs = require('qs');

var app = express();

// The API endpoint to search repositories on GitHub
var url = 'https://api.github.com/search/repositories';

// The params which will search for JavaScript repositories by number of stars
var querystring = '?q=language=javascript&sort=stars&order=desc';

app.get('/', function(req, res) {
  request.get({
    url: url+querystring, 
    // Need to pass in this header while GitHub's search API is in preview-mode
    headers: {'Accept': 'application/vnd.github.preview'}}, function(err, resp, body) {
      if (err)
        console.log(err);
      
      if (body) {
        body = JSON.parse(body);
        var output = '';
        for(i=0; i<body.items.length; i++) {
          output += "Name: " + body.items[i].name;
          output += "\nURL: " + body.items[i].html_url;
          output += "\n-----------------------------------------\n";
        }
        res.end(output);
      }
  });
});

app.listen(80);
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).