I am new to handling promises or async function calls.In my code I am trying to execute command on one remote server and get values in one of my javascript function. I am using below code ,
var SSH = require('ssh2');
var funcdata = getData()
console.log(funcdata)
function getData() {
    var data = 'nodata';
        var ssh = new SSH({
            host: 'xxx.xxx.xxx.xxx',
            user: 'username',
            pass: 'password'
        });
        ssh.exec('ls', {
            out: function(stdout) {data += stdout.toString()},
            exit: function(code) {
                console.log(data) // this works here and i want to return this data value               
            }
        }).start();
        ssh.on('error', function(err) {});
    return data 
}
When i execute, this returns me funcdata as initial value only that is 'nodata'. How can i return the vales which is return from exit in ssh call ? please suggest something.
Thanks
