December 2014
Intermediate to advanced
372 pages
7h 34m
English
CHAPTER 17
![]()
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
Read now
Unlock full access