serve markdown files from a directory as html

npm install markdown-directory
1 downloads in the last week
9 downloads in the last month


serve markdown files from a directory as html

build status


To render some markdown files in articles/, you could write:

var http = require('http');
var fs = require('fs');
var hyperstream = require('hyperstream');
var article = require('markdown-directory')(__dirname + '/articles');

var server = http.createServer(function (req, res) {
    var m = RegExp('^/article/(.+)').exec(req.url);
    if (m) {
        res.setHeader('content-type', 'text/html');

        fs.createReadStream(__dirname + '/article.html')
                'title': m[1],
                '#article': article(m[1]),
    else res.end('beep boop\n')

Now your markdown will be rendered into the article div of article.html:

$ curl -s http://localhost:9000/article/robot
    <div id="article"><h1>robots</h1>
<p>Beep boop.</p>


var mdir = require('markdown-directory')

var article = mdir(dir)

Return a function article(name) for loading markdown files from the base directory dir.

var stream = article(name)

Return a readable stream for the markdown file name + '.markdown'.

stream will emit an 'error' event but it has a default listener that inlines the error message into the output stream so you don't need to worry about handling messages unless you care especially much about setting the http status codes on the response. The 'error' events have a .statusCode property that you can copy onto res.statusCode yourself if you want that.


With npm do:

npm install markdown-directory



npm loves you