I am trying to use fetch API to get my data from a url. I am able to fetch the data from url and perform operations with it. The issue i have is my return statement returns promise pending instead of returning true or false. I am able to use console.log to print result with no problem. Any help will be appreciated.
const fetch = require("node-fetch");
async function load(CLIENT_ID) {
let response = await fetch('<url-hidden>');
let data = await response.json();
let resp_data = checkClientExist(data, CLIENT_ID)
return resp_data
}
function checkClientExist(data, CLIENT_ID) {
for (i = 0; i < data.length; i++) {
if (data[i].CLIENT_ID === CLIENT_ID) {
return true
}
}
return false
}
console.log(load("fa000")) // Returns undefined want it to return either true or false(i.e resp_data from above)
load("fa000").then(response => {
console.log(response)
}) // works fine