Answer the question
In order to leave comments, you need to log in
How to pass API value from Node JS to frontend?
Good afternoon!
As part of the training, I decided to work with the API. I chose the Yandex.Weather service. After a few days of torment, I realized that accessing the API is possible only from the server.
Wrote a script for Node using fetch.
Faced with the fact that I don’t understand how to access / get this result in a JS file, or at least render it to the page
const url =
"https://api.weather.yandex.ru/v2/forecast?lat=55.75396&lon=37.620393&extra=false";
fetch(url, {
method: "GET",
headers: {
"X-Yandex-API-Key": "ключ",
"Content-Type": "application/json; charset=utf-8",
},
})
.then((resp) => resp.json())
.then((data) => {
const temp = `Температура: ${data.fact.temp}`;
const tempFeels = `Ощущается как: ${data.fact.feels_like}`;
console.log(temp, "\n", tempFeels);
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question