title: How can I make code wait for the return of an API call - Node.js
body: <p>I am trying to write a function which makes an API call and wait until the API has returned a value, how do I improve my code to do this. At the moment it just returns Promise-pending.</p>
  <pre><code>async function getData(options){
  
      
      const result = new Promise((resolve, reject) =&gt; {
          request(options, function(error, response) {
          if (error) return reject(error);
              
          return resolve(JSON.parse(response.body));
          });
      });
      
      var fromapi = await result;
      
      return fromapi;
  
  };
      
  </code></pre>