title: Send a json File to a pug template with Express and Node
body: <p>Forgive me but Im still a bit new to express. I have a pug template running a simple homepage. On the same server I have a json file containing a lists of events. I want to send the data in this json file to the pug template and iterate over it in a div. I have used fs to load the file, lodash map to map it to an array. I have created the route for the pug file but I don't know how to link the two together i.e pass the array created in my fs function to the jade route. I have the below so far</p>
  
  <pre><code>var file = __dirname + '/events.json';
  fs.readFile(file, 'utf8', function (err, data) {
  if (err) {
    console.log('Error: ' + err);
    return;
  }
  
  var data = JSON.parse(data);
  
  var newEventList = data.events.map(events =&gt; ({
      id: events.id ,
      name: events.name ,
      venue: events.place.name ,
      address: events.place.location.street + " " + events.place.location.city + " " + events.place.location.zip ,
      coverPicture: events.coverPicture ,
      description: events.description ,
      startTime: events.startTime ,
      endTime: events.endTime
   }));
  });
  
  
  app.get('/', function (req, res) {
   res.render('index', { title: 'Hey', message: 'Hello there!', 
     newEventList })
    })
  </code></pre>
  
  <p>Can anybody point me in the right direction? At the moment I get</p>
  
  <pre><code>ReferenceError: newEventList is not defined
  </code></pre>
  
  <p>So I guess I need a way to make the route see the newEventList array. Thank you.</p>