Mongo Mark

Elvenware Logo



Your MongoMark application should be able to do the following:

The application contains:

There are two main files in the project.


It can read in a markdown file:

var fs = require('fs');
fs.readFileSync('', 'utf8');

After reading in the file it inserts places it insert a JSON object and stores it in a MongoDb database. The JSON object is able to do at least two things:

CreateJson.js can also read the data back from the database. It converts the markdown into html, and sends it to the client browser. An external program called Pandoc handles conversion from markdown to HTML.

But all of that is for later on. For now, just a button click and read in a hard coded file will be fine.


This program uses a small subset of Express. It serves up HTML pages to a browser. There are actually three served up to the client:

All three pages are stored in a directory called Public. They are loaded with code that looks like this:

// Served up as the default page when a request comes from the client.
app.get('/', function(request, result){
      var html = fs.readFileSync(__dirname + '/Public/index.html');
    result.writeHeader(200, {"Content-Type": "text/html"});   

// Give express access to the Public directory
app.use("/", express.static(__dirname + '/Public'));

We use code like this often. If you have place where you store default code, you should paste it in so you can access it again later. The following link provides an overview of the code that follows this pattern:

The Client

The important code on the client is found index.js:

var Run = (function() {

    // Constructor for module pattern
    function Run() {

        // Call the server's app.get('/read', function() {}); function
        $.get('/read', function(data) {
            // do something with HTML sent from the server
        }).error(function(err) {

    // return the constructor.
    return Run;

$(document).ready(function() {
    new Run();    

Here we use the modular pattern.

Turn it In

Place your code in your repository in a directory called Week06-MongoMark. Enter the URL of your repository when you submit the assignment.

Written with StackEdit.