I have a server that emits data at regular intervals of time. I want to use this data in my rest API, How do I fetch it? It needs to be automatically called when the data is pushed from that external source. I have tried the following but it did not work.
var EventSource = require("eventsource");
var url = "..." // Source URL
var es = new EventSource(url);
es.onmessage = (event) => {
console.log(event)
const parsedData = JSON.parse(event.data);
console.log(parsedData)
}
Any help is appreciated.
from How to comsume data from a sse server in Nodejs?
No comments:
Post a Comment