How to handle different error types in node.js

In node world, Error object is passed as a first argument to callback.

What is the proper way to distinguish between error types in node?

Use some attribute (.errorCode, or .userNotFound)?

Have separate (Error-inherited) class and use .constructor / instanceof?

Any other convention I am missing?

You can pass anything, as long as it's not null or undefined it should represent an error.

You could use it any way you like, inherit Error is one way but you could pass an error Number or even an error String, it's really up to you.

A bit too "loose" IMHO but that's how it is.