cli-handle-unhandled is a specialized Node.js utility package designed for command-line interfaces (CLIs) to ensure graceful, yet explicit, termination upon encountering unhandled promise rejections. Currently stable at version 1.1.2, the package has a mature and focused scope, with infrequent but consistent maintenance releases since its initial launch. Its key differentiator lies in its opinionated approach: rather than merely logging an unhandled rejection and allowing the process to continue in an indeterminate state, it registers a handler that explicitly crashes the Node.js process, providing immediate feedback essential for robust CLI tooling. This prevents silent failures that can occur when asynchronous operations reject without a `.catch()` block, making errors transparent to the user or calling environment. It is primarily a CommonJS module, targeting Node.js environments.
npm install cli-handle-unhandledVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to initialize cli-handle-unhandled and triggers an unhandled promise rejection to show its intended behavior of crashing the process.
Understand that this package is meant to terminate the process on unhandled rejections. If you want to *prevent* crashes and handle rejections gracefully without exiting, use `process.on('unhandledRejection', (reason, promise) => { /* custom logging & recovery */ });` without `cli-handle-unhandled`.Ensure your project or file uses CommonJS `require()` to import this package, or configure your build system to handle CJS imports within an ESM context. For Node.js versions 12+, consider dynamic `import()` for CJS modules if absolutely necessary: `const cliHandleUnhandled = await import('cli-handle-unhandled'); cliHandleUnhandled.default();` (assuming a default export when dynamically imported).Use `const cliHandleUnhandled = require('cli-handle-unhandled');` in CommonJS files, or configure your build system to properly handle CommonJS modules within an ES Module environment.Ensure `cliHandleUnhandled()` is called early in your application's lifecycle. Check for other global `process.on('unhandledRejection', ...)` handlers that might be installed after `cli-handle-unhandled` and are preventing the intended crash.No dependency data recorded yet.