title: refactor NodeJs functions
body: <p>I have a big <code>app.js</code> file and want to split the code. I took all my routes into a module called <code>routes.js</code></p>
  
  <pre><code>module.exports = function(app){
  
  app.get('/', function (req, res) {
    res.redirect('/page1');
  });
  
  app.get('/page1', function (req, res) {
    res.render('page1');
  });
  
  app.get('/page2/:id', function (req, res) {
      res.render('page2', {
        val: Number(req.params.id)
      });
  });
  
  }
  </code></pre>
  
  <p>and in my app.js I call</p>
  
  <pre><code>const routes = require('./Server/routes')(app);
  </code></pre>
  
  <p>So this works fine.</p>
  
  <p>I have some functions like</p>
  
  <pre><code>function loadData(id, callback) {
    fs.readFile('./database.json', 'utf8', function (err, data) {
      var json = JSON.parse(data);
      var arr = json.arr;
      var obj = arr.find(e =&gt; e.id === Number(id));
      callback(obj);
    });
  }
  </code></pre>
  
  <p>and want to have them in separate files too. How can I do this? I am able to export one function but how can I export more than one?</p>
  
  <p>Like</p>
  
  <pre><code>module.exports = function(){
  
  function sayHello(){
     console.log("Hello");
  }
  
  function calc(){
     return 5 + 7;
  }
  
  }
  </code></pre>
  
  <p>require the module and call</p>
  
  <pre><code>myModule.sayHello();
  
  var num = myModule.calc();
  </code></pre>