S
S
semki0962019-12-25 21:12:54
JavaScript
semki096, 2019-12-25 21:12:54

How to display data in real time?

There is an api from which you can take dynamic data. I want to build a chart with real time data display. Do I understand correctly that for this you need to run cron every second? Navrno I'm wrong and there are better options. I didn’t work with node.js, but if this is what you need, there will be a reason to study. Tell me please.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Neverov, 2019-12-25
@semki096

1) On the server, every N-seconds make a request to the remote API. Get the data and store it in your database.
2) When you enter the page, give the saved data from the database, and also connect the client to the WebSocket. The easiest way is with the socket.io module .
3) After each update from a third-party API, send data on clients that are connected to the socket.

V
Vladimir Matsuev, 2019-12-25
@vkinder

you can apply setInterval and call to api in it, something like this:

const timerId = setInterval(() => loadFromAPI(), 1000)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question