Nodejs asynchronously loops to obtain all files in the directory

  node.js, question
getDir:function(cb){
 var path=node_path.join(__dirname,dir_path)
 var over=[];
 function forDir(path){
 var fi=fs.readdir(path,function(err,files){
 if(err){
 return false;
 bracket
 async.map(files,function(e,cb){
 var paths=node_path.join(path,e)
 fs.stat(paths,function(err,file){
 if(file.isDirectory()){
 cb(null,paths)
 }else{
 over.push(paths)
 bracket
 })
 },function(err,results){
 results.forEach(function(e,i){
 forDir(e)
 })
 })
 })
 bracket
 forDir(path)
 
 var len=over.length
 var len_one=null;
 var se=false;
 
 var timer=setInterval(function(){
 if(len_one==len){
 clearInterval(timer)
 console.log(over)
 bracket
 if(se){
 len_one=over.length
 se=false
 }else{
 len=over.length
 se=true
 bracket
 
 },500)
 bracket

How to judge the recursion cycle is completed? The above code can’t get the last loop, so I don’t know when to get the directory.

//Get all subdirectory information under the directory
 var node_path=require('path');
 var fs=require('fs');
 //simulate the execution of async.map
 function myMap(arrayData,call,resultCallback){
 var p=arrayData;
 var finalResultData=[];
 var intercall=function(error,resultData){
 watchLength--;
 finalResultData.push(resultData);
 if(watchLength==0){
 resultCallback(null,finalResultData);
 bracket
 };
 var watchLength=p.length;
 for(var i=0;  i< p.length;  I plus)
 (function(index){
 setTimeout(function(){
 call(index,intercall);
 },100);
 }(p[i]));
 bracket
 
 bracket
 
 //Get all file information under the directory
 function getDir(dir_path,finalCallback){
 var path=node_path.join(__dirname,dir_path);
 console.log(path);
 var over=[];
 var watchProcessDir=[];
 watchProcessDir.push(path);
 function judgeAllDone(path){
 watchProcessDir.splice(watchProcessDir.indexOf(path),1);
 //console.log(watchProcessDir.length);
 if(watchProcessDir.length==0){
 //It's all over
 finalCallback(over);
 return true;
 }else{
 return false;
 bracket
 bracket
 
 function forDir(path){
 var fi=fs.readdir(path,function(err,files){
 //console.log(files);
 if(err){
 return false;
 bracket
 if(!  files||files.length==0){
 judgeAllDone(path);
 return;
 bracket
 myMap(files,function(e,cb){
 //console.log('file:' plus e');
 var paths=node_path.join(path,e);
 fs.stat(paths,function(err,file){
 if(file.isDirectory()){
 //If it is a directory, put paths into result and wait for files to traverse before executing [2]
 cb(null,paths)
 }else{
 //If it is a file, set it to an empty string.
 over.push(paths)
 cb(null,'');
 //Move to cb
 //over.push(paths);
 bracket
 });
 },function(err,results){//[2], enter subdirectories for recursion
 if(results.join('')!  =''){
 //Remove empty string
 results=results.filter(function(item){
 return !  !  item;
 });
 watchProcessDir=watchProcessDir.concat(results);
 results.forEach(function(e,i){
 forDir(e);
 });
 bracket
 
 judgeAllDone(path);
 
 })
 })
 bracket
 
 forDir(path);
 
 
 bracket
 
 getDir('../node_modules',function(over){
 Log ('~ ~ ~ done ~ ~ ~ filesize: percentage d',over.length);
 });