title: How to store variables from node-fetch
body: <p>I'm writing a small project to get data from DynamoDB using node-fetch and then later to present that data back to the user using Dialogflow. Below is an example of my code and is currently working as it's getting the data I need.</p>
  
  <pre><code>  function getstock(agent) {
      const product = agent.parameters.product;
      const prodid = parseInt(product, 10);
      var url = 'link';
      var data = {
        "prodid": prodid
      };
      fetch(url, { 
        method: 'POST', 
        body:JSON.stringify(data),
        headers: {
          'Content-Type': 'application/json'
        }
      }).then((resp) =&gt; {
          resp.json();
      }).then((data) =&gt; {
        console.log(data);
      });
    }
  </code></pre>
  
  <p>But I'm having trouble of assigning that data into a variable so that way I can use <code>agent.add('blah blah ${variable_name}')</code>. I've read several posts and I believe the issue is that I'm not using async/await function. However, I'm relatively new to this sort of stuff and any help would be greatly appreciated. </p>
  
  <p><strong>EDITED</strong></p>
  
  <p>I've updated my code above to use async/await</p>
  
  <pre><code>async function getstock(agent) {
    const product = agent.parameters.product;
    const prodid = parseInt(product, 10);
    var url = 'link';
    var data = {
      "prodid": prodid
    };
    const response = await fetch(url, { 
      method: 'POST', 
      body:JSON.stringify(data),
      headers: {
        'Content-Type': 'application/json'
      }
    });
    const jsondata = await response.json();
    return jsondata;
    }
  
  getstock(agent)
    .then(response =&gt; {
    let prodStock = response.Item.stock;
    let prodName = response.Item.product;
    console.log("the data is" + prodStock);
    agent.add(`The ${prodName} stock is ${prodStock}`);
  }).catch(err =&gt; {
    console.log('error');
  });
  </code></pre>
  
  <p>The code above is now doing what I expect it to do which was to fetch data and to later store that data into a variable so that I can present it back to the user as previosly when storing it to a variable it would just say 'undefined' and this could be becuase I wasn't using async/await. Is there anyway else that I can improve this code/tidy up?</p>