-1

Original question is what difference is there if i call a function without callback or with callback

i am using ssh2 library to list directory on remote sftp server for that there is a function "readdir"

if i call readdir as below it works all perfect

readdir(path, (err, list)=>{
         console.log(list); //list have all data as it should be
}

but if i call function like this (to use it normally in async function)

list= readdir(path);

above code return error from ssh2 dependency ssh2-streams

error is

cb is not a function
cb(undefined, stream); 

1 Answers1

0

If you check the source at https://github.com/mscdex/ssh2/blob/master/lib/protocol/SFTP.js, you will see that this function is describe as a callback function. You need to put the parameters as in the first case if you don't want to raise an error.

nyandog26
  • 1
  • 2