I am reading a folder of images and want to get images name. But the problem here is I am getting empty array in response whereas I have checked by console I should get array of files name. Where am I going wrong?
app.get("/getImages",function(req,res){
    var folderName = './multiuploads/';
    var new_files   = [];     
    fs.readdir(folderName, (err, files) => {        
        for(var j=0;j<files.length;j++){
            console.log(files[j]) // this is giving me name of files
            new_files.push(files[j]);   // but this is not working                   
        }       
      }); 
      console.log(new_files); // this is coming blank
      res.send(new_files);
})
I am using this api to read image files from folder but the problem is that new_files array is still empty even though folder has some images.
 
     
     
     
    