Skip to content

forbital/github-token

Repository files navigation

@forbital/github-token

npm-version npm-downloads

Obtain GitHub Token from various location.

  1. ~/.config/hub
  2. ~/.config/gh/config.yml
  3. GH_TOKEN
  4. GITHUB_TOKEN

Install

yarn add @forbital/github-token
# or npm i --save @forbital/github-token

Use

CLI

echo $(github-token)

or

eval $(github-token --shell)
# then
echo $GITHUB_TOKEN

or

echo "$(github-token --env)" >> .env

direnv

# .envrc
eval $(github-token --shell)

Node.js

import getToken from "@forbital/github-token";

const user = await fetch("https://api.github.com/user", {
  headers: { Authorization: `Bearer ${getToken()}` },
}).then((res) => res.json());

console.log(user.twitter_username);