Hope that it may help you.
Possible duplicate: https://stackoverflow.com/a/21459809/5228251
Below function is been taken from the ^above link.
var _getAllFilesFromFolder = function(dir) {
var filesystem = require("fs");
var results = [];
filesystem.readdirSync(dir).forEach(function(file) {
file = dir+'/'+file;
var stat = filesystem.statSync(file);
if (stat && stat.isDirectory()) {
results = results.concat(_getAllFilesFromFolder(file))
} else results.push(file);
});
return results;
};
usage: _getAllFilesFromFolder(__dirname + '/' + 'foldername');
^ the above function returns results as an array containing paths of every single file in that 'foldername' directory..
and parse it according to the js/jquery library (configs) you're using on client-side before render.
and then you may use any js library to display in tree structure on client-side. I have used jstree in my project few months back. You may use any other as well like jquery-fileTree or etc.
use jade / html (whatever you want) with express to render the resultant data to view.
Here is my code to convert the retrieved into tree (directory) structure format:
https://gist.github.com/narainsagar/79d742ab9c62e29a81d1b1bba804782f
Thanks.