When we say about the Node.js application , you will face four types of errors generally:
- (1)Standard JavaScript Errors: i.e. < EvalError>, < SyntaxError>, < TypeError>, < URIError>, < RangeError>, < ReferenceError> etc.
- (2)System Errors
- (3)User-specified Errors
- (4)Assertion Errors
Node.js Errors Example 1
Lets take first example to deploy our first standard JavaScript Error - ReferenceError.
File: errorexample1.js
//This will throws with ReferenceError due to undefined b
try {
const a = 1;
const c = a + b;
} catch (err) {
console.log(err);
}
Now open the Node.js command and run the below command
node errorexample1.js
Node.js Errors Example 2
File: timererrorexample2.js
const fs = require('fs');
function nodeStyleCallback(err, data) {
if (err) {
console.error('There was an error', err);
return;
}
console.log(data);
}
fs.readFile('/some/file/that/does-not-exist', nodeStyleCallback);
fs.readFile('/some/file/that/does-exist', nodeStyleCallback);
Now open the Node.js command and run the below command
node timererrorexample2.js