await is only valid in async function

I wrote this code in lib/helper.js

var myfunction = async function(x,y) {
   ....
   return [variableA, variableB]
}
exports.myfunction = myfunction;

and then I tried to use it in another file

 var helper = require('./helper.js');   
 var start = function(a,b){
     ....
     const result = await helper.myfunction('test','test');
 }
 exports.start = start;

I got an error

“await is only valid in async function”

What is the issue?

12 Answers
12

Leave a Comment