title: Share variables between files in Node.js?
body: <p>Here are 2 files:</p>
  <pre><code>// main.js
  require('./module');
  console.log(name); // prints &quot;foobar&quot;
  
  // module.js
  name = &quot;foobar&quot;;
  </code></pre>
  <p>When I don't have &quot;var&quot; it works. But when I have:</p>
  <pre><code>// module.js
  var name = &quot;foobar&quot;;
  </code></pre>
  <p>name will be undefined in main.js.</p>
  <p>I have heard that global variables are bad and you better use &quot;var&quot; before the references. But is this a case where global variables are good?</p>