Exploring the types of errors
As we learned in the first chapter, Node.js is a single-threaded application. This means that if an error occurs and we don’t properly handle it, the application will crash. This is why it is important to handle errors properly.
There are two main types of errors in Node.js: syntax errors and runtime errors.
Syntax errors
Syntax errors are thrown when the code is parsed and it is not valid. These errors are thrown by the JavaScript engine, and they are usually easy to fix. Many IDEs and code editors can detect these errors and highlight them in the code editor, so you can fix them before running the application. In our case, we have been using StandardJS as a linter (which is a tool that helps us detect syntax errors and enforce a consistent code style) in previous chapters.
This is an example of a syntax error:
executeThisFunction()
The previous code will throw a ReferenceError
error because the executeThisFunction
function is...