title: TypeError: fn is not a function. Difference between two functions in module.exports
body: <p>I'm trying to use function from other file to make asyn/await wrap for routing. Details:</p>
  
  <ul>
  <li>everything works without wrap function</li>
  <li>second func with time works fine with similar code of export</li>
  <li>wrap function works fine when located in users file</li>
  </ul>
  
  <p>Question: What have I missed and how make wrap work from server file? Thanks for hint in advance.</p>
  
  <p>server.js</p>
  
  <pre><code>let express = require('express');
  let userRules = require('./private/routes/users');
  app.use('/user', userRules);
  
  function asyncWrap(fn) {
      return (req, res, next) =&gt; {
          fn(req, res, next).catch(next);
      };
  }
  function getCurrentTime() {
    return getDateTime(); //inner func
  }
  exports.getCurrentTime= getCurrentTime;
  exports.asyncWrap = asyncWrap;
  </code></pre>
  
  <p>users.js</p>
  
  <pre><code>let express = require('express');
  let router = express.Router();
  const server = require('../../server');
  router.post('/auth', server.asyncWrap(async (req, res, next) =&gt; { //this line throws error
      let user = await sql.getUserByEmail(req.body.email); 
      console.log(server.getCurrentTime()+req.body.email+" tried to auth"); // this works
      ...
  }));
  </code></pre>
  
  <p>Error</p>
  
  <pre><code>TypeError: server.asyncWrap is not a function
  18|dev     |     at Object.&lt;anonymous&gt; (/var/www/gowarranty/serverNode/forfun/private/routes/users.js:145:54)
  18|dev     |     at Module._compile (module.js:571:32)
  18|dev     |     at Object.Module._extensions..js (module.js:580:10)
  18|dev     |     at Module.load (module.js:488:32)
  18|dev     |     at tryModuleLoad (module.js:447:12)
  18|dev     |     at Function.Module._load (module.js:439:3)
  18|dev     |     at Module.require (module.js:498:17)
  18|dev     |     at require (internal/module.js:20:19)
  18|dev     |     at Object.&lt;anonymous&gt; (/var/www/gowarranty/serverNode/forfun/private/routes/index.js:11:13)
  18|dev     |     at Module._compile (module.js:571:32)
  18|dev     |     at Object.Module._extensions..js (module.js:580:10)
  18|dev     |     at Module.load (module.js:488:32)
  18|dev     |     at tryModuleLoad (module.js:447:12)
  18|dev     |     at Function.Module._load (module.js:439:3)
  18|dev     |     at Module.require (module.js:498:17)
  18|dev     |     at require (internal/module.js:20:19)
  18|dev     |     at Object.&lt;anonymous&gt; (/var/www/gowarranty/serverNode/forfun/server.js:5:14)
  18|dev     |     at Module._compile (module.js:571:32)
  18|dev     |     at Object.Module._extensions..js (module.js:580:10)
  18|dev     |     at Module.load (module.js:488:32)
  18|dev     |     at tryModuleLoad (module.js:447:12)
  18|dev     |     at Function.Module._load (module.js:439:3)
  18|dev     |     at Object.&lt;anonymous&gt; (/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js:78:21)
  18|dev     |     at Module._compile (module.js:571:32)
  18|dev     |     at Object.Module._extensions..js (module.js:580:10)
  18|dev     |     at Module.load (module.js:488:32)
  18|dev     |     at tryModuleLoad (module.js:447:12)
  18|dev     |     at Function.Module._load (module.js:439:3)
  18|dev     |     at Module.runMain (module.js:605:10)
  18|dev     |     at run (bootstrap_node.js:427:7)
  18|dev     |     at startup (bootstrap_node.js:151:9)
  18|dev     |     at bootstrap_node.js:542:3
  </code></pre>