title: Express (sequelize) export async function
body: <p>I'm very new to express / NodeJS in general. I started to write a little application, providing a REST API. The whole thing should work like this:</p>
  
  <ul>
  <li>the request gets routed (routes.js)</li>
  <li>in routes.js, a function in a controller gets called</li>
  <li>since my controller contains the app's logic, it should return data that gets sent with res.json(CONTROLLER_FUNCTION()).</li>
  </ul>
  
  <p>My code:</p>
  
  <p>controller.js</p>
  
  <pre><code>User = require('../models/user')
  
  module.exports.users = function users() {
      users = User.findAll().then(users =&gt; {
      return users;
  });
  </code></pre>
  
  <p>}</p>
  
  <p>routes.js</p>
  
  <pre><code>/* GET users listing. */
  router.get('/', function (req, res, next) {
    res.json(userController.users())
  });
  </code></pre>
  
  <p>So when my route gets called, nothing happens. I believe that happens because my controller logic is async. Probably I have to implement something like a wrapper/callback function (?)</p>
  
  <p>So basically my question is: what is the "right" way to handle a situation like this? How should my code look like?</p>
  
  <p>Example:
  What I normally would do is to pass to userController.users a function, that gets called when the async action is done (.then).</p>
  
  <p>routes.js</p>
  
  <pre><code>/* GET users listing. */
  router.get('/', function (req, res, next) {
    userController.users((data) =&gt; res.json(data));
  });
  </code></pre>
  
  <p>controller.js</p>
  
  <pre><code>User = require('../models/user')
  
  module.exports.users = function users(send) {
      users = User.findAll().then(users =&gt; {
          send(users);
      });
  }
  </code></pre>
  
  <p>Is this the best way to do this? / Is this considered good practice? Is it even recommended to not put my code directly into routes.js?</p>