# ghutils

> A collection of utility functions for dealing with the GitHub API

Latest version **5.0.17** (published 2026-11-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install ghutils
pnpm add ghutils
yarn add ghutils
bun add ghutils
```

## Health

**Score 65/100 (B)** — status: active.

Positive: esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 5.0.17 |
| Published | 2026-11-03 |
| First published | 2015-05-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 30.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 20 |
| Author | Rod |
| Maintainers | rvagg |

## Links

- npm: https://www.npmjs.com/package/ghutils
- Repository: https://github.com/rvagg/ghutils
- Homepage: https://github.com/rvagg/ghutils#readme
- Issues: https://github.com/rvagg/ghutils/issues
- npm.io page: https://npm.io/package/ghutils

## Recent versions

- 5.0.17 (latest) — 2026-11-03
- 5.0.16 — 2026-10-27
- 5.0.15 — 2026-10-19
- 5.0.14 — 2026-08-05
- 5.0.13 — 2026-07-30
- 5.0.12 — 2026-07-29
- 5.0.11 — 2026-07-29
- 5.0.10 — 2026-07-29
- 5.0.9 — 2026-07-21
- 5.0.8 — 2026-07-07
- 5.0.7 — 2026-06-29
- 5.0.6 — 2026-06-22
- 5.0.5 — 2026-06-04
- 5.0.4 — 2026-04-28
- 5.0.3 — 2026-04-28
- … 19 more at https://npm.io/package/ghutils/versions

## README

# ghutils

**A collection of utility functions for dealing with the GitHub API**

[![NPM](https://nodei.co/npm/ghutils.svg?style=flat&data=n,v&color=blue)](https://nodei.co/npm/ghutils/)

Used by:

* [ghissues](https://github.com/rvagg/ghissues) - a Node.js library to interact with the GitHub Issues API
* [ghpulls](https://github.com/rvagg/ghpulls) - a Node.js library to interact with the GitHub Pull Request API
* [ghrepos](https://github.com/rvagg/ghrepos) - a Node.js library to interact with the GitHub Repos API
* [ghusers](https://github.com/rvagg/ghusers) - a Node.js library to interact with the GitHub Users API
* [ghteams](https://github.com/rvagg/ghteams) - a Node.js library to interact with the GitHub Teams API
* [ghreleases](https://github.com/ralphtheninja/ghreleases) - a Node.js library to interact with the GitHub Releases API

## Requirements

- Node.js >= 20

## Example

```js
import { ghget, lister } from 'ghutils'

const auth = { token: 'your-github-token' }

// Make a single GET request
const { data } = await ghget(auth, 'https://api.github.com/user')
console.log(data)

// List all items from a paginated endpoint
const issues = await lister(auth, 'https://api.github.com/repos/owner/repo/issues')
console.log(issues)
```

## API

All methods return Promises and use native `fetch` internally.

### apiRoot

The API root URL: `'https://api.github.com'`

### makeOptions(auth, options)

Helper to build request options with proper headers. Accepts a GitHub auth object from [ghauth](https://github.com/rvagg/ghauth) (containing a `token` property) and optional additional options.

### ghget(auth, url, options)

Make a GitHub API compatible GET request to the given URL. Returns `{ data, res }` where `data` is the parsed JSON response and `res` is the fetch Response object.

```js
const { data, res } = await ghget(auth, 'https://api.github.com/user')
```

### ghpost(auth, url, data, options)

Make a GitHub API compatible POST request with JSON body.

```js
const { data } = await ghpost(auth, 'https://api.github.com/repos/owner/repo/issues', {
  title: 'New issue',
  body: 'Issue description'
})
```

### ghpatch(auth, url, data, options)

Make a GitHub API compatible PATCH request with JSON body.

```js
const { data } = await ghpatch(auth, 'https://api.github.com/repos/owner/repo/issues/1', {
  state: 'closed'
})
```

### ghdelete(auth, url, options)

Make a GitHub API compatible DELETE request.

```js
await ghdelete(auth, 'https://api.github.com/repos/owner/repo/issues/1/labels/bug')
```

### lister(auth, urlbase, options)

Given a paginated URL resource, recursively fetch all available pages of data and return an array containing the complete list.

Options:
- `afterDate` - A `Date` object; only return items with `created_at` after this date
- Any other options are passed as query parameters (e.g., `state`, `per_page`)

```js
// Get all open issues
const issues = await lister(auth, 'https://api.github.com/repos/owner/repo/issues', {
  state: 'open',
  per_page: 100
})

// Get issues created after a specific date
const recentIssues = await lister(auth, 'https://api.github.com/repos/owner/repo/issues', {
  afterDate: new Date('2024-01-01')
})
```

## Authentication

All methods accept an `auth` object with a `token` property. Use [ghauth](https://github.com/rvagg/ghauth) to create and manage persistent GitHub authentication tokens for command-line apps:

```js
import ghauth from 'ghauth'

const auth = await ghauth({
  configName: 'my-app',
  clientId: 'your-github-oauth-app-client-id',
  scopes: ['repo']
})
// auth = { token: 'ghp_xxxxxxxxxxxx', user: 'username' }
```

Or provide the token directly:

```js
const auth = { token: 'ghp_xxxxxxxxxxxx' }
```

For backwards compatibility with older versions, an object with both `user` and `token` properties is also accepted (the `user` property is ignored).

## License & Copyright

**ghutils** is Copyright (c) 2015-2025 Rod Vagg [@rvagg](https://twitter.com/rvagg) and licensed under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md file for more details.

---
_Source: https://npm.io/package/ghutils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
