title: How can I transfer a variable from a javascript file to another html file in node.js?
body: <p>I have a project in node.js that is designed to read off data from a google spreadsheet, and store that data in an array, which is then used in embedded javascript in an html file. I eventually want to host this node.js project on heroku, which has been sucesseful thus far. The problem is that everything I have tried to do this has either not worked in node.js, or caused my project to not work on heroku when I hosted it. Here is the code from my javascript file, index.js:</p>
  
  <pre><code>const express = require('express');
  const GoogleSpreadsheet = require('google-spreadsheet');
  const path = require('path');
  const PORT = process.env.PORT || 5000;
  const { promisify } = require('util');
  
  const creds = require( './clients_secret.json');
  
  var len;
  
  
  function printVoter(voter){
      len++;
  }
  
  async function accessSpreadsheet(){
      const doc = new GoogleSpreadsheet('1q-jrxsY3GUy5KlEvVE6BkXW4BhNYA7QL-Su9seJNY_8');
      await promisify(doc.useServiceAccountAuth)(creds);
      const info = await promisify(doc.getInfo)();
      const sheet = info.worksheets[0];
  
      const rows = await promisify(sheet.getRows)({
          offset: 1
      })
  
      rows.forEach(row =&gt; {
          printVoter(row);
      })
      global.arrx = new Array(99);
      rows.forEach(row =&gt; {
          arrx.push(`${row.regnumber}`);
      })
      arrx.forEach(x =&gt; console.log(x));
    console.log(arrx);
  
  }
  
  accessSpreadsheet();
  
  
  
  
  express()
    .use(express.static(path.join(__dirname, 'public')))
    .set('views', path.join(__dirname, 'views'))
    .set('view engine', 'ejs')
    .get('/', (req, res) =&gt; res.render('pages/index'))
    .listen(PORT, () =&gt; console.log(`Listening on ${ PORT }`))
  </code></pre>
  
  <p>The variable I have been trying to transfer is arrx, a local variable inside of the accessSpreadsheet function. </p>