Skip to content

Instantly share code, notes, and snippets.

@magdiel01
Created August 31, 2014 13:19
Show Gist options
  • Save magdiel01/4e826a5545a48965c01d to your computer and use it in GitHub Desktop.
Save magdiel01/4e826a5545a48965c01d to your computer and use it in GitHub Desktop.
GitHub repos by user
var https = require('https');
var getRepos = function(username, callback) {
var options = {
host: 'api.github.com',
path: '/users/' + username + '/repos',
method: 'GET',
headers: {
'user-agent': 'nodejs'
}
};
var request = https.request(options, function(response) {
var body = '';
response.on('data', function(chunk) {
body+= chunk.toString('utf8');
});
response.on('end', function() {
var repos = [];
var json = JSON.parse(body);
json.forEach(function(repo) {
repos.push({
name: repo.name,
description: repo.description
});
});
callback(repos);
});
});
request.end();
};
getRepos('henryreyes', function(repos) {
console.log('Henry has ' + repos.length + ' repos');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment