title: How to return values read using Google Sheets API spreadsheets.values.get?
body: <p>I'm currently working on a project in which I extract values from a Google Sheet. I am able to <code>console.log</code> the results which shows that I can access the values. However, when I try to return it to the larger node.js script for processing in other functions, the variable is still undefined when it should be an array of strings.  </p>
  
  <p>Here is the code I'm struggling with.</p>
  
  <pre><code>function extractValsTest(auth) {
  const sheets = google.sheets({version: 'v4', auth});
  var request = {
      spreadsheetId: //id,
      range: 'A1:B1'
  }
  var test = new Array();
  test = sheets.spreadsheets.values.get(request, function(err, response){
      if (err) return err;
      test1 = String(response.data.values).split(',');
      console.log(test1);
      return test1;
  });
  console.log('Test = ' + test);}
  </code></pre>
  
  <p>Clearly, the value of <code>test</code> should be the value of <code>test1</code>, but instead it is undefined, while the <code>console.log</code> of <code>test1</code> outputs the values that I want in test. </p>
  
  <p>I've tried many different ways to get the values outside of the sheet function, such as returning, overriding a pre-existing variable in the function, and pushing the values to a pre-existing array.</p>
  
  <p>I would be open to using another http client, but I can't work out the authorization required. Any links to Google projects done in other http clients would help as well.    </p>
  
  <p>Any help would be appreciated. Thanks in advance.</p>