Something like this, no third party libs necessary. Fairly simple really.
/*jshint node:true */
function loadPosts(callback) {
'use strict';
var allHtml = ''; //Declare an html results variable within the closure, so we can collect it all within the functions defined within this function
fs.readdir("_posts/", function (err, files) {
function loadPost(name) {
fs.read("_posts/" + name, 'utf8', function (err, data) {
allHtml += mark(data);//Append the data from the file to our html results variable
if (files.length) {
loadPost(files.pop()); //If we have more files, launch another async read.
} else {
callback(allHtml); //If we're out of files to read, send us back to program flow, using the html we gathered as a function parameter
}
});
}
loadPost(files.pop());
});
}
function doSomethingWithHtml(html) {
'use strict';
console.log(html);
}
loadPosts(doSomethingWithHtml);