O'Reilly logo

Pro Express.js by Azat Mardan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 17

image

Domain and Express.js

The domain module is a core Node.js module (http://nodejs.org/api/domain.html) that aids developers in tracking and isolating errors, often a daunting task, through the use of domains. Think of domains as a smarter version of try/catch statements1.

Defining the Problem

To illustrate the hurdle that asynchronous code might introduce to error handling and debugging, look at this synchronous code that prints “Custom Error: Fail!” as we would expect:

try {  throw new Error('Fail!');} catch (e) {  console.log('Custom Error: ' + e.message);}

Now, let’s add asynchronous code in the form of the setTimeout() function

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required