title: How to export a function from other file in NodeJS
body: <p>I have two files:</p>
  
  <p><strong>myService.js</strong></p>
  
  <pre><code>const Period= require('./period');
  const myService = module.exports = {};
  
  const defaults = {
      heating: new Period('heating', 'Oct', 15, 'Mar', 1),
      cooling: new Period('cooling', 'Apr', 15, 'Sep', 15)
  };
  
  const periods = {
      AustraliaDefault: {
          heating: new Period('heating', 'Jul', 1, 'Aug', 31), 
          cooling: new Period('cooling', 'Sep', 1, 'Mar', 1)
      }
  };
  
  myService.getPeriod = function (site, key) {
      return Promise.all([
          myService.findHeat(site, key),
          myService.findCool(site, key)
      ]).spread(function (heating, cooling) {
          return { heating: heating, cooling: cooling };
      });
  };
  
  myService.findHeat = function (site, key) {
      return Promise.resolve(periods[key] &amp;&amp; periods[key]['heating'] || defaults['heating']);
  };
  myService.findingCoolingSeason = function (site, key) {
      return Promise.resolve(periods[key] &amp;&amp; periods[key]['cooling'] || defaults['cooling']);
  };
  </code></pre>
  
  <p>and <strong>Breakdown.js</strong></p>
  
  <pre><code>...
  const myService = require('./myService');
  ...
  
  check('no use of heating during summer', function (report) {
      const model = report.findSection('Breakdown').model;
      const heatingSeries = _.findWhere(model.series, { name: 'Space heating' });
      if (!heatingSeries || model.series.length === 1) {
          return;
      }
  
      const totalAccounts = _.size(report.asModel().accountNumbers);
      const warnings = _.compact(_.map(['May', 'Jun'], function (monthLabel) {
          const summerIndex = _.indexOf(model.xAxis, monthLabel);
          const heatingSummerCost = heatingSeries.data[summerIndex];
          if (heatingSummerCost &gt; (totalAccounts * maxSum)) {
              return {
                  month: monthLabel,
                  cost: heatingSummerCost,
                  accounts: totalAccounts
              };
          }
      }));
      this.should(!warnings.length, util.format('breakdown chart indicates heating (%s) in summer (%s) in %d account(s)', _.pluck(warnings, 'cost'), _.pluck(warnings, 'month'), totalAccounts));
  }),
  </code></pre>
  
  <p>The first file must describe the seasons(summer, winter) which are different between northern and southern hemisphere.
  I must call somehow <strong>myService</strong> in <strong>Breakdown</strong> . If it is let as default, it will detect that there is use of heating in summer (because in default in takes the northern hemisphere seasons) but it must be able to check for which one to compute it.</p>
  
  <p>What I've tried is to import myService into Breakdown and instead of mapping <code>['May', 'Jun']</code> to use <code>myService.findHeat</code> or <code>myService.Seasons</code> and others but it doesn't work. It lets them as <code>undefined</code> no matter what method I use.</p>
  
  <p>Any suggestions?</p>