I have an express server running on nodejs. I have a file structure that I want to turn into a list of links. I've included my recursive file structure functions.
file structure functions
function fileTreeWrapper (root, callback) {
output = recursiveFileTree(root);
console.log(output);
callback();
}
function recursiveFileTree (root) {
fs.readdir('./' + root, function (err, files) {
if(err) throw err;
var structure = '';
var folders = '';
var tests = '';
structure += '<ul>';
for(var i in files) {
if(files[i].indexOf('.') === -1) {
folders += '<li id="folder">' + root + '/' + files[i] + '">' + files[i].charAt(0).toUpperCase() + files[i].slice(1);
folders += recursiveFileTree(root + '/' + files[i]);
folders += '</li>';
} else if (files[i].indexOf('.js') > -1) {
tests += '<li id="file"><a href="' + root + '/' + files[i] + '">' + files[i] + '</a></li>';
}
}
structure += folders;
structure += tests;
structure += '</ul>';
return structure;
});
}
I call router.get like so:
router.get('/', [function (req, res, next) {
fileTreeWrapper('rootFolder', function() {
next();
});
}, function (req, res) {
res.render('Files & Folders', {
title: 'Main',
localTitle: 'Choose a File',
result: output
}, function (err, html) {
if(err) throw err;
res.send(html);
res.end();
});
}]);
However, when I run this, my page shows up blank. My jade template for rendering looks like this:
h1= title
h3= localTitle
div !{result}
Am I using the next() callback inappropriately? Why would this not work?