I want to log all the files in the directory recursively and return a confirmation when all files are logged. Here's the directory structure.
sample
│ app.js
└───Temp1
│ │ temp1.js
│ └───Temp2
│ │ temp2.js
Here's the code
```
let readDirectory = function(dirname){
return new Promise((resolve,reject)=>{
fs.readdir(dirname,(err,files)=>{
if(err) reject(err);
files.forEach(file=>{
fs.stat(`${dirname}/${file}`,(err,stats)=>{
if(stats.isDirectory()){
readDirectory(`${dirname}/${file}`)
}else{
resolve(console.log(file));
}
})
})
})
})
}
readDirectory(sampledir).then(()=>console.log('completed'));
```
Below is the result when I execute this function.
```
app.js
completed
temp1.js
temp2.js
```
Where should I resolve in order to get output as below.
```
app.js
temp1.js
temp2.js
completed
```