Whenever I try making fetch get api calls I am not able to save the result of it in my other JavaScript variables. either nothing happens or I get something like '[object Promise]'. What exactly am I doing wrong in this specific call and/or code?
users.js:
async function githubUsers() {
let response = await fetch('https://api.github.com/users')
let users = await response.json()
console.log(users)
return users
}
githubUsers()
let allUsers= githubUsers()
let UsersWidget = `
<div>
<div>
<p>Current Online users: ${allUsers}</p>
</div>
</div>`
I have a main.js file where I call upon it:
main.js
document.writeln(UsersWidget);
and here is my index.html
<!DOCTYPE html>
<html>
<head>
<title>Github users</title>
<link href="css/tailwind.min.css" rel="stylesheet">
<script type="text/javascript" src="js/users.js"></script>
</head>
<body class="bg-blue-500">
test
</body>
</html>