Node app that tracks contributions to specific GitHub repos.
- Initialize a node application and create a package.json.
npm init -y
- Install "dotenv" and "@octokit/rest" using your favorite package manager.
npm i dotenv
npm i @octokit/rest
- Create a .env.sample file to highlight the keys/tokens you need to access the API. For this project, you will need to login into GitHub and create a Personal Access Token. You can find directions on how to create your Personal Access Token here.
- Create a .env file and paste your access token inside.
- Create a new "start" script in your package.json.
"start": "node index.js",
- Create a new file called index.js and import @octokit/rest and configure dotenv.
require('dotenv').config();
const { Octokit } = require("@Octokit/rest");
- Using your access token, authenticate with the GitHub API.
const octokit = new Octokit({
auth: process.env.PERSONAL_GITHUB_ACCESS_TOKEN,
});
- Now you can use
octokit
to access the GitHub API. For more info on the functions you can use, check out https://octokit.github.io/rest.js/v18.