title: Pass NodeJS callback from exported function to view
body: <p>I'm developing a NodeJS app and have a function being exported like so:</p>
  
  <pre><code>module.exports = {
    userCount: function(done) {
      user.count(function(err, count) {
        done(count);
      });
    }
  }
  </code></pre>
  
  <p>What I'm trying to do is pass the callback to a view. This is how I'm currently doing it:</p>
  
  <pre><code>methods.userCount(function(count) {
    app.get("/", function(req, res) {
      res.render("../views/index", {
        userCount: count
      });
    });
  });
  </code></pre>
  
  <p>That works fine but my problem is there will be multiple functions being exported, therefore, I will need to pass multiple callbacks to the same view.</p>
  
  <p>Is the way I'm currently doing it the best/only way to pass the callback to the view?</p>
  
  <p>The only other way I thought about doing it was to declare a variable and just add the callback to the variable. Something like this:</p>
  
  <pre><code>var num;
  methods.userCount(function(count) {
    num = count;
  });
  
  res.render("../views/index", {
    userCount: num
  });
  </code></pre>
  
  <p>But I'm not sure if that's good practice. Is there a better way to do this?</p>