3.1 Add data folder

mkdir data && touch data/data.json

3.2 Add a JSON File

@ data.json

Use a valid JSON structure similar to:

{
  "speakers": [{
    "title" : "Art in Full Bloom",
    "name": "Lorenzo Garcia",
    "shortname" : "Lorenzo_Garcia",
    "summary" : "Drawing and painting flowers may seem like a first-year art student's assignment, but Lorenzo Garcia brings depth, shadows, light, form and color to new heights with his unique and revolutionary technique of painting on canvas with ceramic glaze. This session is sure to be a hit with mixed media buffs.",
    "description": "<p>Lorenzo was born in Mexico, but grew up in Southern California after his mother immigrated to Los Angeles when he was a year old. His mother worked as a seamstress in the Fashion District and brought home scrap materials for Lorenzo to create his early mixed media art. From that point on, Lorenzo became hooked on creating art from scrap metals, fabrics, wood, canvas, and many others. During his junior year at Bischon Art School in Los Angeles, he perfected his own proprietary method of painting on canvas with ceramic glaze, which he will demonstrate on Monday in his session, 'Art in Full Bloom'.</p><p>Lorenzo paints with an extraordinary amount of color, and prefers to create art centered around nature, animals, and science. Now in his senior year at Bischon, Lorenzo has been creating mixed media totem poles made from old telephone poles, and other recycled materials, and is already planning his next new technique that will likely inspire a trend for years to come.</p>",
    "artwork": ["Lorenzo_Garcia_01_tn.jpg", "Lorenzo_Garcia_02_tn.jpg", "Lorenzo_Garcia_03_tn.jpg", "Lorenzo_Garcia_04_tn.jpg"]
  },{
...
  },...
  ] // NO COMMA AFTER LAST NODE
}

3.3 Require JSON Files

Since the server will need to deliver the JSON content in a response we need to tell it where to find the files.

var dataFile = require('./data/data.json');

3.4 User Defined Port Option

The ExpressJS .set() method allows us to customize the listening port.

app.set('port', process.env.PORT || 3000 );

3.5 Modify server listening function

The ExpressJS .get() method allows us to retrieve variables set for the server.

var server = app.listen(app.get('port'), function() {
  console.log('Listening on port ' + app.get('port'));
});

3.6 Specify a Port During Run-time

PORT=8080 node app.js

3.7 Respond with JSON data

The .get() method allows us to define the response to a get request. It takes in the route and a callback function inside of which anything can happen but the ultimate result is calling the .send() method with some package of content to deliver back to the browser.

app.get('/', function(req, res) {
  var info = '';
  dataFile.speakers.forEach(function(item) {
    info += `
    <li>
      <h2>${item.name}</h2>
      <p>${item.summary}</p>
    </li>
    `;
  });
  res.send(`
      <h1>Roux Academy Meetups</h1>
      ${info}
  `);
});

The .forEach(function(item) {}) method parses the content of the JSON file into dot notation variables.

3.8 Commit changes

git add . && git commit -m