I'm currently facing an issue with my code where I am trying to save the results from looping through an API into a JSON file using writeFileSync. Here is the code snippet in question:
function processRarity(limit) {
var resultJson = [];
for (var i = limit; i < limit + 100; i++) {
const everything = async () => {
const response = await fetch(
"https://api-v2-mainnet.paras.id/token/asac.near::" + i
);
var json = await response.json();
return json;
};
everything().then((res) => {
console.log(res);
resultJson = res;
});
}
fs.writeFileSync(`${basePath}/results.json`, JSON.stringify(resultJson, null, 2));
}
However, when I check the resulting JSON file, all I see is an empty array:
[]