-
Book Overview & Buying
-
Table Of Contents
Mastering Web Application Development with Express
By :
A well-established pattern with the Node programs is to have an error argument as the first parameter of the callback function, since we cannot use try-catch for asynchronous code and we also don't want our programs to break each time an error occurs.
The most common line found in our sample application is the one that checks for an error and returns early by executing the callback function with the error parameter:
if (err) { return callback(err); }
// or:
if (err) { return next(err); }If there is no error, the rest of the code that follows will execute.
Luckily for us, there are some modules that can help us avoid having to write this boilerplate code each time we need to delegate the error to the callback function. These modules are available at the following URLs:
Each of these modules provides a function that takes two parameters and should...
Change the font size
Change margin width
Change background colour