How to send multiple image as response in node.js

i have stored more image in mongodb by using like this

exports.save = function (input, image, callback)
{
    db.collection("articles", function (error, collection)
    {
      collection.save(input, {safe: true}, callback);
    });
}

i have retrieved all image from db.

find().toArray(function(err,result)
{
     console.log(result.length)//length is 5
     for(var i=0;i<results.length;i++)
     {
                res.contentType(results[i].imageType);
                res.end(results[i].image.buffer, "binary");
     }
});

how to convert this image as binary and how to send response to client.i have tried for loop but i got this error can't set header after send res.........how to solve

There is no way to send multiple images within a one single response, I guess. But maybe you could try to merge those images somehow within your loop, and then send a one big image which will consists of your N images merged together.

I have just had a similar problem. You need to pass your 'results' array to a Jade template (for example) or manually create an HTML page with the images that you find (not the data) - rather virtual links to the actual images.

res.render('image_list.jade', {results:results});

Then your template might look like :

block content
  div.container
   header
    h1 Images in a list
   div#images
    - each result in results
   div.myimage
     img(src='http://localhost:3000/oneimage'+result._id)

In your app.js you would need to provide a route /oneimage that returns a single image (data) as you have done in your code (i.e replace findAll(...) with findOne(...., id, ...)