Why to invent the wheel?
There is a very popular NPM package, that let you do things like that easy.
var recursive = require("recursive-readdir");
recursive("some/path", function (err, files) {
// `files` is an array of file paths
console.log(files);
});