title: Nodejs: Global variables across multiple files
body: <p>I have written my code across several files for my node server.</p>
  <p>If I have a file, say basket.js:</p>
  <pre><code>var Basket = {
      fruits : 0,
      
      addFruit : function() {
          fruits++;
      },
  
      removeFruit : function() {
          fruits--;
      },
  
      printFruit : function() {
          console.log(this.fruits);
      }
  }
  module.export = Basket;
  </code></pre>
  <p>And I have another file called give.js:</p>
  <pre><code>var Basket1 = require(&quot;./basket.js&quot;);
  
  Basket1.addFruit();
  Basket1.printFruit();
  </code></pre>
  <p>And another file called take.js:</p>
  <pre><code>var Basket2 = require(&quot;./basket.js&quot;);
  
  Basket2.removeFruit();
  Basket2.printFruit();
  </code></pre>
  <p>Will both files write into the same instance of Basket?
  In other words, will they both have control over the property, fruits?
  Does node manage race conditions on its own? i.e. if two commands to modify fruit come in at the same time from add and sub, does node know how to handle it?</p>
  <p>If I want to make a way in which two files can look at a singleton at the same time and access it, is this the way to go?? Or how else does one do it?</p>