title: Node js - How to serve multiple SVG files to a browser
body: <p>I'm new to Node and server oriented code and am trying to get multiple svg files which are stored in the server.</p>
  
  <p>Here is my code client-side using jQuery:</p>
  
  <pre><code>$.ajax({
    url: someURL,
    data: someData
  })
  .done(function(data) {
    console.log('data got', data);
    callback(null, data);
  })
  .fail(function() {
    callback(new Error('Cannot access files'));
  });
  </code></pre>
  
  <p>And here is my code server side:</p>
  
  <pre><code>// links is an array of links to the different svg files
  var svgs = [];
  async.eachSeries(links, function(link, next) {
    fs.readFile(link, function(err, svg) {
      svgs.push(svg);
      next(err);
    });
  }, function(err) {
    if (err) {
      response.writeHead(500);
      response.end(JSON.stringify(err));
      return;
    }
    response.writeHead(200);
    response.end(svgs); // Doesn't work
    // response.end(svgs[0]); // Works
  });
  </code></pre>
  
  <p>As long as I send only one file to the browser (which seem to be a Buffer instance), everything seems to work fine, but when I try to send multiple ones as an Array the transaction succeed but I got nothing in my returned data. That may be related to the MIME type of what I'm trying to send, but I couldn't find how to handle that.</p>