// This is the example viewer server.
//
// It's purpose is to enable editing the examples
// inside the presentation environment.

var express = require("express");
var bodyParser = require("body-parser");
var fs = require("fs");
var mkdirp = require("mkdirp");
var path = require("path");
var app = express();

app.use(bodyParser.json());
app.use(express.static("."));

app.post("/save", function (req, res){
  var unit = req.body.unit,
      module = req.body.module,
      example = req.body.example,
      html = req.body.html,
      directory = path.join("units", "unit-" + unit, "module-" + module, "example-" + example),
      filename = path.join(directory, "index.html");

  mkdirp(directory, function (err) {
    if (err) return res.send(err);
    fs.writeFile(filename, html, function(err) {
      if (err) return res.send(err);
      res.send("Saved!");
    });
  });
});

app.listen(3000, function () {
  console.log("Listening at http://localhost:3000");
});

@@ -414,108 +414,65 @@
 var 
-unit = req.body.unit,%0A      module = req.body.module,%0A      example = req.body.example,%0A      html =
+directory = path.join(%0A        %22units%22,%0A        %22unit-%22 +
  req
@@ -481,20 +481,20 @@
 ody.
-html
+unit
 ,%0A      
 dire
@@ -493,95 +493,83 @@
     
-directory = path.join(%22units%22, %22unit-%22 + unit, %22module-%22 + module, %22example-%22 + example
+  %22module-%22 + req.body.module,%0A        %22example-%22 + req.body.example%0A      
 ),%0A 
@@ -689,24 +689,24 @@
 .send(err);%0A
-
     fs.write
@@ -720,16 +720,25 @@
 lename, 
+req.body.
 html, fu

Simplify server