wtfnode - Node.js Exit Debugger

0.10.1 · active · verified Sun Apr 19

wtfnode is a utility designed to help Node.js developers diagnose why their applications are not exiting gracefully. It provides enhanced and human-readable insights into active event loop handles, such as timers, sockets, and servers, which prevent a Node.js process from terminating. Leveraging Node's internal `process._getActiveHandles()`, wtfnode breaks down complex handle information into actionable details, including call site origins for listeners, making it easier to pinpoint the exact code keeping a program alive. The current stable version, 0.10.1, functions as a crucial diagnostic tool for stalled applications, differentiating itself from raw Node.js introspection by offering a higher-level, more interpretable view of the event loop. Its release cadence is driven by the community's need for robust debugging solutions for persistent processes.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates module usage by setting up a `setInterval` and an HTTP server, then using `wtf.dump()` to report open handles when the process receives a SIGINT signal.

const wtf = require('wtfnode');

console.log('Starting wtfnode example. Press Ctrl+C to dump handles.');

// Create an interval to keep the process alive
const intervalId = setInterval(() => {
  console.log('Interval running...');
}, 2000);

// Create a server that will also keep the process alive
const http = require('http');
const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello wtfnode!\n');
});

server.listen(3000, () => {
  console.log('HTTP server listening on port 3000.');
});

// Register SIGINT handler to dump handles before exiting
process.on('SIGINT', () => {
  console.log('\n[WTF Node?] Dumping open handles:');
  wtf.dump();
  // To allow clean exit after dump (optional, depending on desired behavior)
  clearInterval(intervalId);
  server.close(() => {
    console.log('Server closed. Exiting process.');
    process.exit(0);
  });
});

console.log('Application running. Check http://localhost:3000 and wait for intervals.');

view raw JSON →