Fetch a GitHub repository's package.json file using the GitHub API
npm install get-repo-package-json --saveThe basics:
const getPackage = require('get-repo-package-json')
getPackage('segmentio/nightmare').then(pkg => { console.log(pkg) })To fetch a specific commit/branch/tag, use a long-form URL:
await getPackage('https://github.com/monkey/business/tree/experiment')Or specify a ref option:
await getPackage('monkey/business', {ref: '0e783153885ed78f71d138085a77644ff8e59aa1'})To see more supported repository string formats, see the github-url-to-object demo.
This package exports a single function that returns a promise.
repository(string) - Any string supported by github-url-to-object.options(optional object)access_token- GitHub API key. Can also be set as aGITHUB_ACCESS_TOKENenvironment variable.ref- The name of the commit/branch/tag. Defaults to nothing, so the GitHub API will return the repo's default branch.
npm install
npm testMIT