title: How to consume data from a sse server in Nodejs?
body: <p>I have a server that emits data at regular intervals. 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 the external source. I have tried the following code but it did not work.</p>
  <pre><code>var EventSource = require(&quot;eventsource&quot;);
  
  var url = &quot;...&quot; // Source URL
      var es =  new EventSource(url);
      es.onmessage = (event) =&gt; {
          console.log(event)
          const parsedData = JSON.parse(event.data);
          console.log(parsedData)
      }
  </code></pre>