DEV Community

Discussion on: Central Error Handling in Express

Collapse
 
briantuju profile image
Brian • Edited

The best error handling mechanism I've seen so far. I have a question though.

I understand that i have to require this in the index file:

const { handleError } = require("path-to-code")

Will I have to include this code

const { ErrorHandler } = require("path-to-code");

in every file where I need to handle errors apart from the index file?

Collapse
 
nedsoft profile image
Chinedu Orie

It's like any other module, you will have to require/import it anywhere you need to use it. No specific exceptions, it depends on the use case.

Collapse
 
briantuju profile image
Brian

Thank you so much