Node.js Error Handling

How to handle errors using Error Object in Node.js?

An error object is an object that is either an instance of the Error, or extends the Error class.

throw new Error('Ran out of coffee')

You can extends Error class like below:

class NotFoundError extends Error {
throw new NotFoundError