title: node js exclude / outsource code snippets in a function
body: <p>i have to routes in node js with nearly the same code. I want to exclude this code in a function, but when i call the function the process (route) don't wait for the return var of the new function. Maybe someone can create an example for me, how i can handle that. I think is something like callback and promise.</p>
  
  <p>Best,</p>
  
  <p>Simon</p>
  
  <p>a pseudo example with express.</p>
  
  <pre><code>function getUser(variable) {
     return variable;
  }
  
  app.get('/user', function(req, res) {
    res.json(getUser(a));
  });
  
  app.get('/users', function(req, res) {
    res.json(getUser(b));
  });
  </code></pre>