I have the below code which call api and get status using node-fetch . I need to use node-fetch 2.6.1 and use the code like .then-->.then cannot able to use async await .
function fetching(){
fetch(jobsurl, requestOptions)
.then(response => response.text())
.then(result => {
console.log("------------the job id is ------------");
console.log(eval(result)[0]["id"])
console.log("\n\n\n\n\n")
console.log("--------------The Job Status is------------");
console.log(eval(result)[0]["status"])
console.log("\n\n\n\n\n")
var job_id=eval(result)[0]["id"].toString();
var stat=eval(result)[0]["status"];
while(stat != "success"){
fetch(jobsurl, requestOptions)
.then(response => response.text())
.then(result => {
console.log("------------the job id is ------------");
console.log(eval(result)[0]["id"])
console.log("\n\n\n\n\n")
console.log("--------------The Job Status is------------");
console.log(eval(result)[0]["status"])
console.log("\n\n\n\n\n")
job_id=eval(result)[0]["id"].toString();
stat=eval(result)[0]["status"];
}
// as it is success so call the main url
fetch()....
}//ftehcing end
now it has stat variable inside then
that give the job status success or pending if it sucess then only I can proceed. But for that I need to iterate and check when it will get success every time. so I used while loop.
But it is not working. as stat value check every time by calling fetch inside it.
Please suggest