X
X
xdvz2021-04-27 18:03:31
JavaScript
xdvz, 2021-04-27 18:03:31

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

1 answer(s)
D
Denioo, 2021-04-27
@Denioo

Read about the RESP API and understand what it is.
https://habr.com/ru/post/483202/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question