Fetch files or list directories from GitHub repositories.
If given a directory path, returns directory listing:
githubGet('eush77/github-get', function (err, files) {
if (err) throw err;
console.log(files);
})
//=> [ '.gitignore',
// '.travis.yml',
// 'LICENSE',
// 'README.md',
// 'cli.js',
// 'index.js',
// 'package.json',
// 'test' ]
If given a file path, returns file contents:
githubGet('eush77/github-get/package.json', function (err, pkg) {
if (err) throw err;
console.log(JSON.parse(pkg).description);
})
//=> 'Fetch files and list directories from GitHub repositories'
All data returned from GitHub API is also available:
githubGet('eush77/github-get/package.json', function (err, pkg, data) {
if (err) throw err;
console.log(data.download_url);
})
//=> 'https://raw.githubusercontent.com/eush77/github-get/master/package.json'
option | description | default value |
---|---|---|
owner |
Owner of the repository (user/organization) | |
repository |
Repository name | |
path |
Path to file or directory in the repository | / (root) |
token |
GitHub token for authentication. Unauthenticated requests to GitHub API are limited to 60 requests per hour. Generate your token here | |
endpoint |
API endpoint | https://api.github.com/ |
owner
, repository
, and path
can either be specified in a path string (first argument) or in the options
.
File contents (array) or directory listing.
Data returned by GitHub API. Object or array of objects, depending on whether path is to a file or a directory.
Install github-get-cli:
$ npm install -g github-get-cli
$ github-get --help
- github-get-cli — CLI for this module.
- npm-get — fetch files and list directories from npm packages.
npm install github-get
MIT