title: Cant make a variable be seen outside of a function in Node js?
body: <p>I need to make the <em>index_to_write</em> variable to be seen outside of the function. How can I make this possible?</p>
  <pre><code>const XlsxPopulate = require('xlsx-populate');
  let found = false;
  let i = 1;
  let index_to_write = 0;
  XlsxPopulate.fromFileAsync(&quot;todo-list.xlsx&quot;)
      .then(workBook =&gt; {
          while (i &lt;= 10 &amp;&amp; found === false){
              const value = workBook.sheet(&quot;Do-Shopping&quot;).cell(&quot;A&quot; + i.toString()).value();
              if (value === undefined) {
                  found = true;
                  index_to_write = i.toString();
              }
              i++;
          }
      });
  console.log(&quot;A &quot; + index_to_write + &quot; is the first one to be free of data&quot;);
  </code></pre>
  <p>I tried to add <code>return index_to_write;</code> below the <code>index_to_write = i.toString();</code> but it does not resolve the problem.</p>
  <p>Currently, it shows 0, as in the initialization, but it should print 4. How to repair it?</p>
  <p>Thank you very much in advanced!</p>