title: Node JS Require undefined functions
body: <p>In writing modular JavaScript code for the first time (slowly converting from Java server code to Node JS), I'm having trouble understanding why this code doesn't work.</p>
  
  <p>Node Server code:</p>
  
  <pre><code>const wceTimer = require('./myTimer');
  
  const http = require('http');
  
  const hostname = '127.0.0.1';
  const port = 3000;
  
  const server = http.createServer((req, res) =&gt; {
      res.statusCode = 200;
      res.setHeader('Content-Type', 'text/plain');
      res.end('Hello World\n');
  });
  
  server.listen(port, hostname, () =&gt; {
      console.log('Server running at http://' + hostname + ':' + port + '/');
      console.log(typeof wceTimer);
      console.log(typeof wceTimer.getTime);
  });
  </code></pre>
  
  <p>Here is my module code:</p>
  
  <pre><code>    var myTimer = (function (){
  
      var currentTimeMS = -1;
      var timerInterval;
  
      function getTime(){
          return currentTime;
      }
  
      function getTimeFormatted(){
          if(currentTime &lt;= 0) {
              return "undefined";
          } else {
              return new Date(currentTimeMS).toUTCString();
          }
      }
  
      function advanceTime(){
          if(currentTime &lt;= 0) {
              this.currentTimeMS = 946684800000;
          } else {
              this.currentTimeMS = this.currentTimeMS + 1000;
          }
      }
  
      function startTimer(){
          timerInterval = setInterval(advanceTime, 3000);
      }
  
      function stopTimer(){
          clearInterval(timerInterval);
      }
  
      return {
          startTimer: startTimer,
          stopTimer: stopTimer,
          getTime: getTime,
          getTimeFormatted: getTimeFormatted
      };
  
  })();
  </code></pre>
  
  <p>Why does line 3 in the server.listen method fail with undefined?
  Why cannot I use the developer console in my browser to call functions on myTimer?</p>