why-is-node-running is a diagnostic utility for Node.js environments, designed to identify active handles (like timers, network connections, and event listeners) that prevent a Node.js process from exiting gracefully. The current stable version is 3.2.2. Releases are active but somewhat irregular, typically driven by Node.js version updates or small feature enhancements and bug fixes. Its key differentiator lies in its ability to pinpoint the exact code locations responsible for these lingering handles, providing stack traces to aid in debugging unexpected process longevity or potential memory leaks, which is crucial for server-side applications and long-running scripts. It supports both programmatic integration and CLI usage, including a convenient `--import` flag for preloading. The package also provides TypeScript type definitions for enhanced developer experience.
npm install why-is-node-runningVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to programmatically use `why-is-node-running` to identify open handles (like `setInterval` and `net.Server`) that prevent a Node.js process from exiting. It intentionally creates multiple handles and then uses `whyIsNodeRunning()` to print a detailed report of these active handles and their associated stack traces to the console.
Migrate your project to use ES modules (`import` syntax and `"type": "module"` in `package.json`) or ensure your Node.js version is 20.11+. For CommonJS projects, explicitly install `why-is-node-running@2.x`.
Instead of `import 'why-is-node-running/include';` in your code, execute your Node.js application with `node --import why-is-node-running/include your-app.js`.
Be aware that stack traces will now show relative paths for files within your project, which can be beneficial for readability across different environments. No fix is required, but adjust expectations for log parsing.
Update your code to use `import whyIsNodeRunning from 'why-is-node-running';` and ensure your project is configured for ESM (e.g., by adding `"type": "module"` to your `package.json` file or renaming files to `.mjs`). If migration is not feasible, downgrade to `why-is-node-running@2.x`.
Ensure you are using a default import: `import whyIsNodeRunning from 'why-is-node-running';`. If in a CJS context (and using v2.x), it would be `const whyIsNodeRunning = require('why-is-node-running');`.No dependency data recorded yet.