Obtain GitHub Token from various location.
~/.config/hub
~/.config/gh/config.yml
GH_TOKEN
GITHUB_TOKEN
yarn add @forbital/github-token
# or npm i --save @forbital/github-token
echo $(github-token)
or
eval $(github-token --shell)
# then
echo $GITHUB_TOKEN
or
echo "$(github-token --env)" >> .env
# .envrc
eval $(github-token --shell)
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);