How to throw a 404 error in express.js?
<p>In app.js, I have</p>

<pre><code>// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});
</code></pre>

<p>so if I request some not exist url like <code>http://localhost/notfound</code>, above code will execute.</p>

<p>In exist url like <code>http://localhost/posts/:postId</code>, I would like to throw 404 error when access some not exist postId or deleted postId.</p>

<pre><code>Posts.findOne({_id: req.params.id, deleted: false}).exec()
  .then(function(post) {
    if(!post) {
      // How to throw a 404 error, so code can jump to above 404 catch?
    }
</code></pre>