How to use server-sent-events in express.js
<p>I setup my REST server with <a href="http://expressjs.com/" rel="noreferrer">express.js</a>. Now I want to add sse to this server. After I implemented <a href="https://www.npmjs.com/package/server-sent-events" rel="noreferrer">this</a> sse package, I get an error. I know that I get this error, when would try to use <code>res.send</code> twice, but I am not.</p>

<pre><code>ERROR: Error: Can't set headers after they are sent.                                            
    at ServerResponse.OutgoingMessage.setHeader (http.js:690:11)                            
    at ServerResponse.header (/home/root/node_modules/express/lib/response.js:718:10)         
    at ServerResponse.send (/home/root/node_modules/express/lib/response.js:163:12)            
    at app.get.str (/home/root/.node_app_slot/main.js:1330:25)                                 
    at Layer.handle [as handle_request] (/home/root/node_modules/express/lib/router/layer.js:95:5)    
    at next (/home/root/node_modules/express/lib/router/route.js:131:13)                       
    at sse (/home/root/node_modules/server-sent-events/index.js:35:2)                          
    at Layer.handle [as handle_request] (/home/root/node_modules/express/lib/router/layer.js:95:5)  
    at next (/home/root/node_modules/express/lib/router/route.js:131:13)                          
    at Route.dispatch (/home/root/node_modules/express/lib/router/route.js:112:3)
</code></pre>

<p>Is it possible that I can't use the express methods anymore within the sse function? For example:</p>

<pre><code>app.get('/events', sse, function(req, res) {
    res.send('...');
});
</code></pre>

<p>Furthermore, I found <a href="https://stackoverflow.com/a/31700443/1754625">this</a> solution and <a href="http://www.smartjava.org/content/html5-server-sent-events-angularjs-nodejs-and-expressjs" rel="noreferrer">this</a>. Is it possible to make sse with the <code>res.write</code> function or in another way without using another package?</p>