title: How to make Express.js log errors during asynchronous operations
body: <p>I have code like this:</p>
  
  <pre><code>exports.listSavedThreads = function (req, res) {
    SavedThread.find({}).exec().then(function (data) {
      wat.map();
      res.render('home/listSavedThreads');
    });
  };
  </code></pre>
  
  <p><code>wat</code> is undefined variable, so the code above doesn't work and <code>res.render()</code> is never called, but nothing is being printed to the console, it fails silently and browser is stuck in an endless loading.</p>
  
  <p>If I do the same without a promise:</p>
  
  <pre><code>exports.listSavedThreads = function (req, res) {
    wat.map();
    res.render('home/listSavedThreads');
  };
  </code></pre>
  
  <p>The error is being printed to the console and the browser, as usual.</p>
  
  <p>The only way I've been able to print an error is by using <code>try/catch</code>:</p>
  
  <pre><code>exports.listSavedThreads = function (req, res) {
    SavedThread.find({}).exec().then(function (data) {
      try {
        wat.map();
        res.render('home/listSavedThreads');
      } catch(e) {
        console.log('Error: ', e);
      }
    });
  };
  </code></pre>
  
  <p>Then in the console I see:</p>
  
  <p><code>Error:  [ReferenceError: wat is not defined]</code></p>
  
  <p>Obviously, I can't put <code>try/catch</code> into every operation, because I mostly need error output for development, so I can see my typos and stuff like that. Is there a way to output errors for all operations, even asynchronous one?</p>