Skip to content

Instantly share code, notes, and snippets.

@l00f00
Forked from miwaniec/download-github-repo.js
Created May 16, 2024 16:09
Show Gist options
  • Save l00f00/4a267b8a33299f19f2755a82ad0866d0 to your computer and use it in GitHub Desktop.
Save l00f00/4a267b8a33299f19f2755a82ad0866d0 to your computer and use it in GitHub Desktop.
Download zipped repository from github. If repo is private, you have to use token (create in user profile).
const request = require('request');
const fs = require('fs');
const repo = 'miwaniec/socket-camera';
const accessToken = ''; /* for private repo, use token - https://github.com/settings/tokens */
var options = {
method: 'GET',
url: 'https://api.github.com/repos/' + repo + '/zipball/',
encoding: 'binary',
headers: {
'Authorization': (accessToken != '' ? 'token ' + accessToken : '' ),
'User-Agent': 'miwaniec-app'
}
};
request(options, function(error, response, body) {
if (error || response.statusCode !== 200) {
console.log('Failed to get repo ', response.statusCode);
} else {
console.log('We got the repo!');
fs.writeFile('repo.zip', body, 'binary', function (err) {});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment