NodeJS : prevent application to crash on error
<p>When an error occurs in NodeJS application, the server may crash and stop if an exception occurs.</p>

<p>How can I prevent this situation so that the server never stops on error, but returns and error code instead ?</p>

<p>--
EDIT</p>

<p>Here is a method which causes a server crash (table foo doesn't exist) :</p>

<pre><code>app.get('/articles/list', function(req, res) {
    connection.query('select * from foo', function(err, rows, fields) {
        if (err) throw err;
        res.send(JSON.stringify(rows));
    });
});
</code></pre>

<p>-- BEST SOLUTION
Finally, I found the best solution for me :
<a href="http://rowanmanning.com/posts/node-cluster-and-express/" rel="nofollow noreferrer">http://rowanmanning.com/posts/node-cluster-and-express/</a></p>

<p>In summary, it consists in using a cluster of server, and to restart a server when it exits</p>