Minimal Node.js process-level error handler utility for uncaught exceptions, unhandled rejections, and warnings. Works in both CommonJS and ESM environments.
- Handles uncaught exceptions, unhandled rejections, and warnings
- Pluggable logger (defaults to @eliware/log)
- Easy to add/remove handlers for testability
- Works in both CommonJS and ESM modules
npm install @eliware/errorsimport { registerHandlers } from '@eliware/errors';
registerHandlers();
// Or with options:
// registerHandlers({ processObj: process, log: customLogger });
// Simulate an uncaught exception
setTimeout(() => { throw new Error('Demo uncaught exception'); }, 1000);const { registerHandlers } = require('@eliware/errors');
registerHandlers();
// Or with options:
// registerHandlers({ processObj: process, log: customLogger });
// Simulate an uncaught exception
setTimeout(() => { throw new Error('Demo uncaught exception'); }, 1000);Registers process-level exception handlers. Returns an object with a removeHandlers function to detach all handlers (useful for testing).
options(optional): An object with the following properties:processObj(optional): The process object to attach handlers to (default:process)log(optional): Logger for output (default: @eliware/log)
- Returns:
{ removeHandlers: () => void }
Type definitions are included:
export declare function registerHandlers(
options?: {
processObj?: NodeJS.Process,
log?: typeof import('@eliware/log')
}
): { removeHandlers: () => void };For help, questions, or to chat with the author and community, visit:


