title: How to get a list of files to the template in Meteor?
body: <p>New to meteor, I'm having a hell of a time with the whole client/server thing. Super fun.</p>
  
  <p>I want to read a list of all files that are in a folder, and just print them on the UI, on a template. It has to be possible. Here's the code.</p>
  
  <p>js file:</p>
  
  <pre><code>var availableFiles = [];
  if (Meteor.isServer) {
      var fs = Npm.require('fs');
      availableFiles = fs.readdirSync(process.env.PWD + '/public/uploads');
      console.log(availableFiles);
  }
  
  Router.map(function() {
  
      this.route('home', {
          path: '/',
          template: 'home',
          data: {files: availableFiles}
      });
  });
  </code></pre>
  
  <p>html file:</p>
  
  <pre><code>&lt;template name="home"&gt;
  {{#each data.files}}
      {{this}}
  {{/each}}
  &lt;/template&gt;
  </code></pre>
  
  <p>I've tried to put the fs calls inside a function on data on the route definition, but I get "Npm is not defined" errors. I don't know if that's how it should be structured or not, remember, newb here. Any help would be greatly appreciated.</p>