title: Packaging JavaScript Functions
body: <p>I'm working to create a shared package of JavaScript functions. At this time, I'm trying to use them like this:</p>
  
  <p><strong>/app/index.js</strong></p>
  
  <pre><code>const myPackage = require('../myPackage');
  
  myPackage.function1();
  myPackage.myScope.function2();
  </code></pre>
  
  <p>The above successfully loads <code>myPackage</code>. However, when I attempt to run <code>function1</code>, I receive an error that says: "TypeError: myPackage.function1 is not a function". My code in the "package" is organized like this:</p>
  
  <pre><code>/myPackage
   index.js
   root
     function1.js
   myScope
     function2.js
  </code></pre>
  
  <p>The code looks like this:</p>
  
  <p><strong>index.js</strong></p>
  
  <pre><code>require('./root/function1.js');
  require('./myScope/function2.js');
  </code></pre>
  
  <p><strong>function1.js</strong></p>
  
  <pre><code>exports.function1 = function() {
    console.log("Doing stuff in function1");
  }
  </code></pre>
  
  <p><strong>function2.js</strong></p>
  
  <pre><code>exports.function2 = function() {
    console.log("Doing stuff for function2");
  }
  </code></pre>
  
  <p>I could understand <code>function2</code> not working because, there's nothing putting it in <code>myScope</code>, which I don't know how to do. However, I don't understand why <code>function1</code> isn't running. What am I doing wrong?</p>