list github repo in javascript

Here's how you can use the Github API to list public repositories using JavaScript and the fetch() function:

index.tsx
async function listRepos(username) {
  const response = await fetch(`https://api.github.com/users/${username}/repos`);
  const data = await response.json();

  data.forEach((repo) => {
    console.log(repo.name);
  });
}

// Example usage:
listRepos('octocat');
262 chars
12 lines

This code sends a GET request to the Github API endpoint for a specific user's repositories, retrieves the JSON response, and iterates through the list of repositories printing the name of each repo to the console. You can replace the listRepos function argument with any Github username to retrieve their public repositories.

gistlibby LogSnag