The module is required for sync or async reading of dir and subdirs.
Installation
npm i recursive-dir-reader
After install, you can require module:
const readdir = require('recursive-dir-reader');
Usage
For example, we have the following directory structure:

In the code below, we gave several examples of how to read this directory and all its subdirectories.
const readdir = require('recursive-dir-reader');
readdir.sync('./someDir', path => {
console.info(path);
});
readdir.async('./someDir', path => {
console.info(path);
});
const filesIntoDirSync = readdir.sync('./someDir');
console.info(filesIntoDirSync);
const filesIntoDirAsync = readdir.async('./someDir');
setTimeout(() => {
console.info(filesIntoDirAsync);
}, 1000);
You can easily combine this methods.
const filesIntoDirAsync = readdir.async('./someDir', path => {
console.info(path);
});
setTimeout(() => {
console.info(filesIntoDirAsync);
}, 1000);