title: How can return data in javascript from SSE flask
body: <p>I am sending data from python Flask (as Server Sent Event) but cant <code>return</code> this data from the function.</p>
  <p>if print to <code>console.log</code> it works but if try to return it it says <code>undefined</code></p>
  <pre><code> let eventSource = new EventSource(&quot;/listen&quot;);
  
        function getData() {
  
          eventSource.addEventListener(&quot;online&quot;, function (e) {
            data = JSON.parse(e.data);
            let station = data.station;
            let finalData = data.data;
            console.log(finalData);
          });
        }
  getData();
  </code></pre>
  <p><code>finalData</code> is what to return to use it in stream graphics so changing <code>console.log(finalData</code> to <code>return finalData</code> shows <code>undefined</code> in console</p>