title: How to display all images from gridfs
body: <p>I was thinking there should be an <code>fs.files.findAll()</code> so I could get all the file names and display it on the page. right now I could only find one at I time and I could display them. I want to have an index page with all the images in the DB.</p>
  
  <pre><code>const mongoose = require("mongoose");
  const Grid = require("gridfs-stream");
  const fs = require("fs");
  const express = require("express");
  const app = express("/")
  mongoose.connect("mongodb://localhost/newDb");
  const conn = mongoose.connection;
  
  app.set("view engine", "ejs"); // set the view engine
  app.use(express.static("public"));
  
  const uploadImages = require("./uploadImages");
  const getAllImages = require("./getAllImages");
  
  
  
  console.log(mongoose.connection.readyState);
  
  app.get("/:img", (req, res) =&gt; {
      getAllImages(conn, req.params.img, res)
  })
  
  app.get("/", (req, res) =&gt; {
      //render all images on page
      //how do I find how many images are in the DB
      //and to get the file names to pass to ejs
      //so I could do forloop to get // img src "/image1.jpg"
  })
  
  app.listen(3000, (err) =&gt; {
      console.log("listening on port 3000")
  })
  </code></pre>
  
  <p>In getAllImages</p>
  
  <pre><code>const mongoose = require("mongoose");
  const Grid = require("gridfs-stream");
  const fs = require("fs")
  function getAllImages(conn, img, response){
      const gfs = Grid(mongoose.connection.db, mongoose.mongo);
      const readStream = gfs.createReadStream({
          filename :img
      })
      readStream.on("error" , function(err){
          console.log("An error: ", err);
      })
      readStream.pipe(response);
      // mongoose.connection.db.listCollections( (err, names) =&gt; {
      //     console.log(names);
      // })
  
  
  }
  module.exports = getAllImages;
  </code></pre>