title: phantomjs SVG server response
body: <p>I've a phantomjs server which loads a page do some d3 visualization. I was able to do the visualization things work but my problem is how to write the final html to response. My code is below.</p>
  
  <pre><code>// server.js
  
  service = server.listen(8124, function (request, response) {
  console.log('Request received at ' + new Date());
  
  response.statusCode = 200;
  response.headers = {
      'Cache': 'no-cache',
      'Content-Type': 'text/plain;charset=utf-8',
      'Content': ''
  };
  
  var req = JSON.parse(request.post);
  
  visualize();
  response.write(??) // 
  
  });
  
  // app.js
  var webPage = require('webpage');
  var page = webPage.create();
  
  function visualize() {
     page.open("./index.html", function() {
     var ret = page.evaluate(function() {
           // Do some SVG work
         });
         console.log(ret); // &lt;svg&gt;&lt;g&gt;&lt;/g&gt;&lt;/svg
         // at this point I am sure that the ret is an html svg element. How can I write this to response?
     });            
  
  }
  </code></pre>