Nodejs promise then The function parameter in NODEJS PROMISE THEN is incorrectly reported as undefined

  node.js, question

I wrote a piece of code according to the following sample code

var promise=require("bluebird")
 
 var promise = new Promise(function(resolve, reject) {
 resolve(1);
 });
 
 promise.then(function(val) {
 console.log(val);  // 1
 Return val plus 2;
 }).then(function(val) {
 console.log(val);  // 3
 });

I wrote the following

var http=require("http")
 var fs=require("fs")
 var promise=require("bluebird")
 var directory="D:/ccav/"
 
 function handle_incoming_request(req,res){
 load_album_list_async(directory).then(isDir_async(filesArray)).then(function(onlyDirArray){
 var opt={"error":null,data:onlyDirArray}
 Console.log ("request:" add req.method add ""add req.url ");
 res.writeHead(200,{"Content-type":"application/json","Charset":"UTF-8"});
 Res.end(JSON.stringify(opt) plus "\n");
 }).catch(function(err){console.error(err)})
 bracket
 
 
 function load_album_list_async(dir){
 return new promise(function(resolve,reject){
 fs.readdir(dir,function(err,filesArray){
 if(err){reject(err)}else{resolve(filesArray)}
 })
 })
 bracket
 
 function isDir_async(filesArray){
 return new promise(function(resolve,reject){
 var onlyDirArray=[];
 for(var i=0;  i<filesArray.length;  I plus)
 fs.stat(filesArray[i],function(err,stats){
 if(stats.isDirectory()){
 onlyDirArray.push(filesArray[i]);
 bracket
 })
 bracket
 resolve(onlyDirArray)
 })
 bracket
 
 var s=http.createServer(handle_incoming_request);
 s.listen(80)

The operation will report an error, and there will be no problem if then in the middle is removed:

load_album_list_async(directory).then(isDir_async(filesArray)).then(function(onlyDirArray){
 ^
 ReferenceError: filesArray is not defined

After searching the Internet for half a day, there is no similar code to refer to. Ask the Great God for advice. How should I write it?

Load _ album _ list _ async (directory). where does then (isdir _ async (filearray)) filearray come from?
 Load _ album _ list _ async (directory). then (isdir _ async)

in addition

function isDir_async(filesArray){
 return new promise(function(resolve,reject){
 var onlyDirArray=[];
 for(var i=0;  i<filesArray.length;  I plus)
 fs.stat(filesArray[i],function(err,stats){
 if(stats.isDirectory()){
 onlyDirArray.push(filesArray[i]);
 bracket
 })
 bracket
 resolve(onlyDirArray)
 })
 bracket

It doesn’t work here. You will resolve the array before it is finished. Either encapsulate fs.stat and promise.All (). Or use async.