var express = require('express'),
    fs = require('fs');
var router = express.Router();

// TODO: Switch to API calls like originally planned
var readFile = function(fname) {
  return fs.readFileSync(fname, 'utf8', function(err, data) { return data; });
};

var fileName = 'resume.json';
var fetchData = function(key) {
  return JSON.parse(readFile(fileName))[key];
};

/* Display resume */
router.get('/', function(req, res, next) {
  var data = {
    contact: fetchData('contact'),
    toolbox: fetchData('toolbox'),
    experience: fetchData('experience'),
    activities: fetchData('activities'),
    education: fetchData('education')
  };
  res.render('resume', data);
});

module.exports = router;

var express = require('express'),
    fs = require('fs'),
    http = require('http');
var router = express.Router();

var fetchAll = function(callback) {
  http.get({
    host: 'localhost',
    port: 3000,
    path: '/data'
  }, function(response) {
    var body = '';
    response.on('data', function(d) { body += d; });
    response.on('end', function() {
      var parsed = JSON.parse(body);
      return callback(parsed);
    });
  });
};

/* Display resume */
router.get('/', function(req, res, next) {
  // TODO: make callback take an error node first
  fetchAll(function(data) {
    res.render('resume', data);
  });
});

module.exports = router;

Switch to using our API call for the data fetch
Switch to using our API call for the data fetch
