title: How to specify HTTP error code using Express.js?
body: <p>I have tried:</p>
  
  <pre><code>app.get('/', function(req, res, next) {
      var e = new Error('error message');
      e.status = 400;
      next(e);
  });
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>app.get('/', function(req, res, next) {
      res.statusCode = 400;
      var e = new Error('error message');
      next(e);
  });
  </code></pre>
  
  <p>but always an error code of 500 is announced.</p>