I am getting directory information through ssh and am exporting some details to be stored in db.
// details.js
const SSH = require('simple-ssh');
const config = require('./config');
let count = 0;  
let update; 
const ssh = new SSH({
        host: config.host,
        user: config.user,
        pass: config.pass});
ssh.start(); 
getInfo(config.dirpath);
function getInfo(dir){
return new Promise(function(resolve,reject){
    ssh
        .exec(`date '+%F %r' -r  ${dir}`,{
            out: function (stdout) 
            {  update = stdout
            },
            err: function (stderr) { console.log(stderr); 
            } 
            })
        .exec(`ls ${dir}/ ` ,{
              out: function (stdout) 
             {stdout = stdout.split("\n"); 
               for (var i =0; i < stdout.length; i++){
                childinfo(dir+"/"+stdout[i]);
            }},
            err: function (stderr) { console.log(stderr); } 
        })  
     resolve(update)
  )}     
}
function childinfo(dirName){
 return new Promise(function(resolve,reject){
    ssh
      .exec(`ls  ${dirName} | wc -l `,{
        out: function (stdout) 
        {  count = count + parseInt(stdout);
           resolve(count);
      },
        err: function (stderr) { console.log(stderr);}
    })
})
}
module.exports ={
   getInfo,
   childInfo
}
The values are exported before it can be updated. I tried using async-await and Promises. Following this.
I am getting reject message even though all console.logs are being executed properly.
I am new to javascript and hence not able to use async-await properly.
//export.js
const fileInfo = require('./details.js');
const config = require('./config');
async function getAllDetails(){
   let d = await fileInfo.getInfo(config.path);
   let c = await fileInfo.childInfo();
   return [d,c];
}
(async function(){
       let info = await getAllDetails();
       console.log(info[1]);
})();
