DEV Community

Arhan Khan
Arhan Khan

Posted on

Build a GitHub Profile Finder App with JavaScript

GitHub has a free public API that returns a user's profile — their avatar, bio, follower count, and public repos — without any login. A profile finder is a great second API project, because it teaches you to turn one API response into a small profile card.

What you are building

An app where you type a GitHub username and get a profile card: avatar, name, bio, followers, following, and public repo count. If you are learning to code and want a structured place to practise, the free Python section on Skill Library is a good next step after a project like this — the same fetch-and-display pattern works in Python too, once you know the basics.

The JavaScript: one fetch, one card

async function findUser(username) {
  const status = document.querySelector('#status');
  const card = document.querySelector('#profile-card');
  status.textContent = 'Searching...';
  card.innerHTML = '';

  try {
    const res = await fetch('https://api.github.com/users/' + username);
    if (!res.ok) throw new Error('User not found');
    const user = await res.json();

    card.innerHTML =
      '<img src="' + user.avatar_url + '" width="80" alt="avatar" />' +
      '<h2>' + (user.name || user.login) + '</h2>' +
      '<p>' + (user.bio || 'No bio yet.') + '</p>' +
      '<p>Followers: ' + user.followers +
      ' | Following: ' + user.following +
      ' | Repos: ' + user.public_repos + '</p>' +
      '<a href="' + user.html_url + '" target="_blank">View on GitHub</a>';
    status.textContent = '';
  } catch (err) {
    status.textContent = 'No GitHub user named "' + username + '" was found.';
  }
}

document.querySelector('#search-btn').addEventListener('click', () => {
  const username = document.querySelector('#username-input').value.trim();
  if (username) findUser(username);
});
Enter fullscreen mode Exit fullscreen mode

Show the repos too

const reposRes = await fetch('https://api.github.com/users/' + username + '/repos?sort=updated&per_page=5');
const repos = await reposRes.json();
repos.forEach((repo) => {
  console.log(repo.name, '—', repo.stargazers_count, 'stars');
});
Enter fullscreen mode Exit fullscreen mode

One extra call gives you the five most recently updated repos. Listing them under the profile card turns a demo into something genuinely useful.

Watch the rate limit

Unauthenticated requests to the GitHub API are limited to 60 per hour per IP address. That is plenty for learning, but if your app suddenly stops working after a lot of testing, you have probably hit the limit — wait an hour, or add a personal access token to raise it.

The one thing to remember

user.name can be null — many GitHub users never set a display name. The || user.login fallback is a one-line habit that stops your card from ever showing a blank heading.

Top comments (0)