Error handling in Node.js

-

Introduction

Due to the asynchronous, event based system of Node.js, the approach to error handling is slightly different when compared to many other backend lanagauges.

When dealing with javascript you often deal with multiple nested callbacks therefore leaving room for uncaught errors and thus your Node.js application falls over.

Catching non-asynchronous errors

The above code uses a try-catch statement to ensure that the error is handled safley.

Catching asynchronous errors

The wrong way:

The right way:

Tips and Tricks

Forever is a script for that detects when your server falls over and automatically restarts it therefore keeping your server up and running.

Comments

Visitor stats.