JavaScript:nodeJS: how to get result data from an async method inside a non-async method : i had read several posting,and even some guide in google and tried. however its not solving my problem.
please kindly help me get through this.

lets get into the code :

i would need to be able to print the result data in line 12 at least

but currently it return me null

and if possible, could i get my result in line 15?


    var serialport = require('serialport');
    var i=0;
    
    processGpsData();
    
    function processGpsData() {
    
    	getData().then(result => {
    		console.log("result: "+result); //<<<<line 12
    	});
    	// await getData(i);
    	console.log(result);// line 15
    	console.log("done");
    	process.exit();
    }
    
    
    async function getData(){
      
    	var port = new serialport("/dev/ttyACM0",{baudRate: 9600});
    	port.on('open', function () {
    
    		process.stdin.resume();
    		process.stdin.setEncoding('utf8');
    	});
    
    	port.on('error', function (err) {
    		console.error(err);
    		process.exit(1);
    	});
    
    
    
    	var test="";
    	var counter=0;
    	port.on("data",function(data){
    		counter++;
    		test +=data;
    
    		if(counter>30){
    			console.log("test1:  "+test);
    			// return test; //need return this, but not working
    			port.close();
    			// resolve(test);
    			return test;
    		}
    	});
      	// return new Promise(resolve => port.on("close", resolve));
    
     }
    
    
   