Here is my initial attempt:
const fetch = require('node-fetch');
...
const getUserData = async function() {
return await fetch('http://jsonplaceholder.typicode.com/users');
}
const usersStore = getUserData();
console.log(usersStore)
I get the result: Promise { <pending> }
Confused that I still got a Promise pending, I tried this:
const usersStore = getUserData()
.then(res => res.json())
.then(json => json);
but got the same result, so I tried this:
const getUserData = function() {
const url = 'http://jsonplaceholder.typicode.com/users';
return new Promise((resolve, reject) => {
const result = fetch(url)
.then(response => response.json)
.then((json) => json);
return resolve(result);
});
}
Still same result.
The only thing that worked was an IIFE, but I didn't want to use that just to get my data.