title: How to resolve the Syntax error : await is only valid in async function?
body: <p>I have written a code to return some data from asynchronous call using promise. While I try to execute I get "Syntax Error await is only valid in async function" and also I get Cannot proxy application requests...Error: connect ECONNREFUSED. </p>
  
  <p>I'm unsure why I get these errors</p>
  
  <p>I have tried using async before the function calls, but it didn't work</p>
  
  <pre><code>var http = require('https');
  var httpGet = function(url) {
    return new Promise (function(resolve, reject) {
      http.get(url,function(res) {
        res.setEncoding('utf8');
        var body = ''; 
        res.on('data', function(chunk){ 
          body += chunk;
          console.log("The body is "+ body);
        });
        res.on('end',function(){resolve(body);});
      }).on('error', reject);
    });
  };
  
  var body = await httpGet('link');
  $.response.setBody(body);
  </code></pre>
  
  <p>I would want variable body to have the data returned from the httpGet function. Right now I'm getting the above mentioned errors. But without using await, I get the value of body as '{}'.</p>
  
  <p>Please help</p>