title: How to create a streaming API with NodeJS
body: <p>How would you go to create a streaming API with <a href="http://nodejs.org" rel="noreferrer">Node</a>? just like the <a href="http://apiwiki.twitter.com/Streaming-API-Documentation" rel="noreferrer">Twitter streaming API</a>.</p>
  
  <p>What I want to do ultimately is get the first update from the <a href="http://friendfeed.com/api/" rel="noreferrer">FriendFeed api</a>, and stream when a new one becomes available (if the id is different), and later on expose it as a web service so I can use it with WebSockets on my website :).</p>
  
  <p>So far I have this:</p>
  
  <pre><code>var sys = require('sys'),
      http = require('http');
  
  var ff = http.createClient(80, 'friendfeed-api.com');
  var request = ff.request('GET', '/v2/feed/igorgue?num=1', 
                           {'host': 'friendfeed-api.com'});
  
  request.addListener('response', function (response) {
      response.setEncoding('utf8'); // this is *very* important!
      response.addListener('data', function (chunk) {
          var data = JSON.parse(chunk);
          sys.puts(data.entries[0].body);
      });
  });
  request.end();
  </code></pre>
  
  <p>Which only gets the data from FriendFeed, creating the Http server with node is easy but it can't return a stream (or I haven't yet found out how).</p>