Skip to content
Sign upLog in
← Back to Community
how to fix Only absolute URLs are supported??
Profile icon
NewCoder2976

const fetch = require('node-fetch');

const array = [10, 20, 30];
const chaydi = [
"https://kodaktor.ru/api/m/",
"https://kodaktor.ru/api/MS2/",
"https://kodaktor.ru/api/MS3/",
];
let data_result = '';
async function array_promises(array, chaydi) {
const headers = { "Content-Type": "application/json" };

for( let i of array){
let request = await fetch(chaydi[i] + array[i] + '/', {headers})
.then(data => data.json);
data_result.push(request.result);
}
return result;
};
result = array_promises(array, chaydi);
console.log(data_result);

Voters
Profile icon
NewCoder2976
Comments
hotnewtop
Profile icon
RayhanADev

Okay so you have several problems:

for( let i of array){

it doesn't work quite like that, try this:

for(i = array.length - 1; i > 0; i--) {

and then when you fetch, your api is not giving a json response. Change the .json() to .text() and see what it says. It's very weird so solve that and it should work :D!

Profile icon
NewCoder2976

@RayhanADev
thanks for helping me. I'm trying to fix this.

Profile icon
RayhanADev

@NewCoder2976
no problemo!

Profile icon
RayhanADev

Well first off, I don't think its relevant to your current problem but line 15:

.then(data => data.json);

should be:

.then(data => data.json());

and then on line 9:

let data_result = '';

I assume you want to push to an array not string so it should be:

let data_result = [];

Give me a few and I'll figure out your problem too :)