title: NodeJS files is not defined
body: <p>I am trying to display on page the image/(images) which I already uploaded,but it says that files is not defined. </p>
  
  <pre><code>app.get('/profile',(req,res) =&gt;{
  gfs.files.find().toArray((err, files) =&gt; {
      // Check if files
      if (!files || files.length === 0) {
        res.render('profile', {files: false})
  
      } else 
      {
          files.map(file =&gt; {
              if(file.contentType === 'image/jpeg' || file.contentType === 'image/png'){
                  file.isImage = true;
              } else {
                  file.isImage = false;
              }
          });
          res.render('profile',{files: files})
      }
    });
  </code></pre>
  
  <p>I am using EJS view engine. profile.ejs
  My code:</p>
  
  <pre><code>  &lt;div class="container"&gt;
          &lt;div class="row"&gt;
            &lt;div class="col-md-6 m-auto"&gt;
              &lt;form action="/upload" method="POST" enctype="multipart/form-data"&gt;
                &lt;div class="custom-file mb-3"&gt;
                  &lt;input type="file" name="file" id="file" class="custom-file-input"&gt;
                  &lt;label for="file" class="custom-file-label"&gt;Upload your image&lt;/label&gt;
                &lt;/div&gt;
                &lt;input type="submit" value="Submit!" class="btn btn-primary btn-block"&gt;
              &lt;/form&gt;
              &lt;hr&gt;
               &lt;% if(files){ %&gt;
                &lt;% files.forEach(function(file) { %&gt;
                  &lt;div class="card card-body mb-3"&gt;
                    &lt;% if(file.isImage) { %&gt;
                      &lt;img src="image/&lt;%= file.filename %&gt;" alt=""&gt;
                      &lt;% } else { %&gt;
                        &lt;%= file.filename %&gt;
                          &lt;% } %&gt;  
                      &lt;/div&gt;
                  &lt;% }) %&gt;
                    &lt;% } else { %&gt;
                      &lt;p&gt;No files to show&lt;/p&gt;
                      &lt;% } %&gt;
        &lt;/div&gt;
    &lt;/div&gt;
  </code></pre>
  
  <p>I don't understand why I always get this error that files is not defined.
  ReferenceError: C:\Users\User\Desktop\Oauth\views\profile.ejs:111</p>
  
  <pre><code>    109|         &lt;/form&gt;
  
      110|         &lt;hr&gt;
  
      111|          &lt;% if(files){ %&gt;
  files is not defined
  </code></pre>