# github4

> NodeJS wrapper for the GitHub API

Latest version **1.1.1** (published 2016-06-06) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

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

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2016-06-06 |
| First published | 2015-12-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+7 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 29 |
| Author | Mike de Boer |
| Maintainers | kaizensoze |

## Links

- npm: https://www.npmjs.com/package/github4
- Repository: https://github.com/kaizensoze/node-github
- Issues: https://github.com/kaizensoze/node-github/issues
- npm.io page: https://npm.io/package/github4

## Dependencies (3)

- [mime](https://npm.io/package/mime.md) ^1.2.11
- [follow-redirects](https://npm.io/package/follow-redirects.md) 0.0.7
- [https-proxy-agent](https://npm.io/package/https-proxy-agent.md) ^1.0.0

## Recent versions

- 1.1.1 (latest) — 2016-06-06
- 1.1.0 — 2016-05-10
- 1.0.0 — 2016-04-29
- 0.6.0 — 2016-04-20
- 0.5.5 — 2016-04-13
- 0.5.4 — 2016-02-26
- 0.5.3 — 2016-02-15
- 0.5.2 — 2016-02-14
- 0.5.1 — 2016-01-25
- 0.4.0 — 2016-01-09
- 0.3.0 — 2016-01-04
- 0.2.20 — 2016-01-04
- 0.2.19 — 2016-01-04
- 0.2.18 — 2016-01-03
- 0.2.17 — 2016-01-03
- … 13 more at https://npm.io/package/github4/versions

## README

##### This fork has been merged into the upstream ([mikedeboer/node-github](https://github.com/mikedeboer/node-github)). Use that instead.

# Node-github

A Node.js wrapper for GitHub API.

## Installation

Install via [npm](https://www.npmjs.com/package/github4) ![NPM version](https://badge.fury.io/js/github4.svg)

```bash
$ npm install github4
```

or

Install via git clone

```bash
$ git clone git@github.com:kaizensoze/node-github.git
$ cd node-github
$ npm install
```

## Documentation

Client API: [https://kaizensoze.github.io/node-github/](https://kaizensoze.github.io/node-github/)  
GitHub API: [https://developer.github.com/v3/](https://developer.github.com/v3/)

## Test auth file

Create test auth file for running tests/examples.

```bash
$ > testAuth.json
{
    "token": "<TOKEN>"
}
```

## Example

Get all followers for user "defunkt":
```javascript
var GitHubApi = require("github4");

var github = new GitHubApi({
    // optional
    debug: true,
    protocol: "https",
    host: "github.my-GHE-enabled-company.com", // should be api.github.com for GitHub
    pathPrefix: "/api/v3", // for some GHEs; none for GitHub
    timeout: 5000,
    headers: {
        "user-agent": "My-Cool-GitHub-App" // GitHub is happy with a unique user agent
    }
});
github.users.getFollowingForUser({
    // optional:
    // headers: {
    //     "cookie": "blahblah"
    // },
    user: "defunkt"
}, function(err, res) {
    console.log(JSON.stringify(res));
});
```

## Authentication

Most GitHub API calls don't require authentication. As a rule of thumb: If you can see the information by visiting the site without being logged in, you don't have to be authenticated to retrieve the same information through the API. Of course calls, which change data or read sensitive information have to be authenticated.

You need the GitHub user name and the API key for authentication. The API key can be found in the user's _Account Settings_.

```javascript
// basic
github.authenticate({
    type: "basic",
    username: USERNAME,
    password: PASSWORD
});

// OAuth2
github.authenticate({
    type: "oauth",
    token: AUTH_TOKEN
});

// OAuth2 Key/Secret
github.authenticate({
    type: "oauth",
    key: CLIENT_ID,
    secret: CLIENT_SECRET
})
```

Note: `authenticate` is synchronous because it only stores the
credentials for the next request.

Once authenticated you can update a user field like so:
```javascript
github.users.update({
    location: "Argentina"
}, function(err) {
    console.log("done!");
});
```

### Creating tokens for your application
[Create a new authorization](https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization) for your application giving it access to the wanted scopes you need instead of relying on username / password and is the way to go if you have [two-factor authentication](https://github.com/blog/1614-two-factor-authentication) on.

For example:

1. Use github.authenticate() to auth with GitHub using your username / password
2. Create an application token programmatically with the scopes you need and, if you use two-factor authentication send the `X-GitHub-OTP` header with the one-time-password you get on your token device.

```javascript
github.authorization.create({
    scopes: ["user", "public_repo", "repo", "repo:status", "gist"],
    note: "what this auth is for",
    note_url: "http://url-to-this-auth-app",
    headers: {
        "X-GitHub-OTP": "two-factor-code"
    }
}, function(err, res) {
    if (res.token) {
        //save and use res.token as in the Oauth process above from now on
    }
});
```

## Update docs/tests

```bash
$ node lib/generate.js
```

Dev note for updating apidoc for github pages:

```bash
$ npm install apidoc -g
$ apidoc -i doc/ -o apidoc/
```

## Tests

Run all tests

```bash
$ npm test
```

Or run a specific test

```bash
$ npm test test/issuesTest.js
```

## LICENSE

MIT license. See the LICENSE file for details.

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