source-githubstats
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

GitHub Stats

A simple package to fetch GitHub user stats without needing to open a browser. Use this in your Node.js applications to retrieve public GitHub user information such as followers, public repositories, and more!

Installation

You can install the package via npm or yarn:

npm install source-githubstats
yarn add source-githubstats

Usage

You can use githubstats with CommonJS or ES Modules.

CommonJS (Classic Node.js)

const { GithubStats } = require("githubstates");
const dotenv = require("dotenv");
dotenv.config();
const token = process.env.token;

const stats = new GithubStats(token);
async function getStats(username) {
  try {
    const Stats = await stats.getUserStats(username);
    console.log(Stats);
  } catch (error) {
    console.error("Error fetching stats:", error);
  }
}
getStats("MrKhelil");

ES Modules (ESM)

import { GithubStats } from "githubstates";
import dotenv from "dotenv";
dotenv.config();
const token = process.env.token;

const stats = new GithubStats(token);
async function getStats(username) {
  try {
    const Stats = await stats.getUserStats(username);
    console.log(Stats);
  } catch (error) {
    console.error("Error fetching stats:", error);
  }
}
getStats("MrKhelil");

Example Output

{
  login: 'MrKhelil',
  id: 144062404,
  node_id: 'U_kgDOCJY3xA',
  avatar_url: 'https://avatars.githubusercontent.com/u/144062404?v=4',
  gravatar_id: '',
  url: 'https://api.github.com/users/MrKhelil',
  html_url: 'https://github.com/MrKhelil',
  followers_url: 'https://api.github.com/users/MrKhelil/followers',
  following_url: 'https://api.github.com/users/MrKhelil/following{/other_user}',
  gists_url: 'https://api.github.com/users/MrKhelil/gists{/gist_id}',
  starred_url: 'https://api.github.com/users/MrKhelil/starred{/owner}{/repo}',
  subscriptions_url: 'https://api.github.com/users/MrKhelil/subscriptions',
  organizations_url: 'https://api.github.com/users/MrKhelil/orgs',
  repos_url: 'https://api.github.com/users/MrKhelil/repos',
  events_url: 'https://api.github.com/users/MrKhelil/events{/privacy}',
  received_events_url: 'https://api.github.com/users/MrKhelil/received_events',
  type: 'User',
  user_view_type: 'public',
  site_admin: false,
  name: 'Khelil Badro',
  company: 'Source',
  blog: '',
  location: null,
  email: null,
  hireable: true,
  bio: 'Full-Stack Dev',
  twitter_username: null,
  public_repos: 1,
  public_gists: 0,
  followers: 1,
  following: 1,
  created_at: '2023-09-04T19:49:26Z',
  updated_at: '2025-04-03T05:07:38Z'
}

Methods

getUserStats(username : string) Fetches the public GitHub stats for the given username.

  • Args username (String) — The GitHub username of the user whose stats you want to fetch.
  • Retruns A Promise with the user stats as a JSON object (like followers, public repos, etc.).

Authentication

To fetch GitHub user stats, you need a GitHub personal access token. You can generate one by following these instructions:

Once you have the token, use it as shown in the examples.

Contributing

If you have suggestions or improvements, feel free to open issues or pull requests. We welcome contributions!

Bugs and Issues

If you encounter any bugs or issues, please open an issue on the GitHub repository.

Created with ❤️ by MrKhelil

npm npm npm github

Package Sidebar

Install

npm i source-githubstats

Weekly Downloads

21

Version

1.0.5

License

MIT

Unpacked Size

9.65 kB

Total Files

5

Last publish

Collaborators

  • badrokhelil