I am very new to JAVASCRIPT so please forgive me if this is a basic question.
I am making a very simple api call:
const getWorldTotal = async () => {
const response = await fetch('https://health-api.com/api/v1/covid-19/total');
const myJson = await response.json();
console.log(myJson)
}
getWorldTotal();
I keep getting an error saying:
Access to fetch at 'https://health-api.com/api/v1/covid-19/total' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
So then I did the following:
const getWorldTotal = async () => {
const response = await fetch('https://health-api.com/api/v1/covid-19/total',{
mode: 'no-cors'
});
const myJson = await response.json();
console.log(myJson)
}
getWorldTotal();
But I still get the following error:
Uncaught (in promise) SyntaxError: Unexpected end of input
at getWorldTotal on line 42
line 42 is the following const myJson = await response.json();
I am not sure what I did wrong?