Answer the question
In order to leave comments, you need to log in
How to send data from backend to frontend?
Generally a question. How to send data from the backend to the frontend and how to receive it there?
Answer the question
In order to leave comments, you need to log in
There are two main ways:
1. Request data from the front over http using XMLHttpRequest or Fetch . For this method, it is necessary to have an endpoint on the server that can generate and send data to the corresponding request.
2. send data at the request of the server via a websocket connection previously established by the client. There are many different approaches for this way, for example:
- the simplest (but not the best). The client has a listener for incoming messages via ws, which parses them and determines what to do with them next
- more difficult to implement. An event bus that you organize yourself (or using third-party libraries) (can be organized on ws and even on http) In this case, you call the ws.emit("event name", data) event on the server (or client) and on the opposite side, catch this event ws.on(ws.emit("event name", (data)=>{ here you process the received data}).
- more difficult to implement. Same event bus, but with the ability to create something like channels to which you can subscribe certain groups of customers)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question