Diagnostic Reports in Node.js

Diagnostic reports in Node.js provide a JSON-formatted snapshot of the runtime state, including JavaScript and native stack traces, heap statistics, platform details, resource usage, and system limits. They are designed for development, testing, and production environments to help identify and resolve issues. Reports can be triggered automatically on uncaught exceptions, fatal errors, and signals, or programmatically via API calls.

process.report.writeReport()process.report.getReport()--report-uncaught-exception / --report-on-fatalerror / --report-on-signal

~2 min read · Updated Dec 30, 2025

1. Introduction


Diagnostic reports capture runtime information when errors occur or when triggered manually. They include details about Node.js internals, system resources, and the execution environment.


2. Report Generation


  • Command-line flags: --report-uncaught-exception, --report-on-fatalerror, --report-on-signal.
  • Signal-based triggering (default: SIGUSR2).
  • Programmatic API: process.report.writeReport() and process.report.getReport().

3. Report Content


  • Header: Event type, timestamp, PID, Node.js version, OS details.
  • JavaScript stack: Captures the error stack trace.
  • Native stack: Low-level C++/V8 stack frames.
  • Heap statistics: V8 memory usage and heap spaces.
  • Resource usage: CPU, memory, page faults, file system activity.
  • libuv handles: Active async, timers, TCP connections, etc.
  • Environment variables: Current process environment.
  • User limits: OS-imposed resource limits.
  • Shared objects: Loaded system libraries.

4. Example


try {
  process.chdir('/non-existent-path');
} catch (err) {
  process.report.writeReport(err);
}

5. Report Versions


  • Version 5: Memory unit values changed to bytes.
  • Version 4: Added ipv4 and ipv6 fields to endpoints.
  • Version 3: Added memory usage keys to resourceUsage.
  • Version 2: Worker thread support.
  • Version 1: Initial release.

6. Configuration


Runtime configuration is available via process.report properties:


  • reportOnFatalError: Trigger on fatal errors.
  • reportOnSignal: Trigger on signals.
  • reportOnUncaughtException: Trigger on uncaught exceptions.
  • signal: Define the signal used for triggering.
  • filename and directory: Control output location.
  • excludeNetwork and excludeEnv: Exclude network or environment data.

7. Worker Thread Integration


Worker threads can generate reports just like the main thread. Reports include information about all child workers, ensuring a complete view of the runtime state.


Conclusion


Diagnostic reports in Node.js are a powerful tool for debugging and monitoring. By capturing detailed runtime information, they help developers analyze failures, optimize performance, and maintain stability in production systems.


Written & researched by Dr. Shahin Siami

Related Articles

Comprehensive Guide to the Node.js VM Module (node:vm)

The node:vm module allows you to compile and execute JavaScript code inside isolated V8 contexts — essentially creating lightweight sandboxes within your Node.js application. These contexts have their own global scope and can run code independently from the main environment. However, vm is NOT a security sandbox. It is powerful for dynamic code execution, template engines, REPLs, plugin systems, and controlled module execution, but it must never be used to run untrusted code.

Continue

Comprehensive Guide to the V8 Module in Node.js (node:v8)

The node:v8 module exposes low-level APIs that interact directly with the V8 JavaScript engine embedded in Node.js. . These APIs provide access to heap statistics, heap snapshots, coverage tools, serialization mechanisms, V8 flags, object queries, and promise lifecycle hooks. The module is essential for performance analysis, memory debugging, tooling, and advanced Node.js internals work.

Continue

Comprehensive Guide to Node.js Worker Threads (node:worker_threads)

The node:worker_threads module enables true multithreading in Node.js by running JavaScript in separate threads. While Node.js is traditionally single‑threaded, worker threads allow CPU‑intensive tasks to run in parallel without blocking the event loop. They support shared memory, zero‑copy transfers, worker pools, resource limits, and advanced synchronization APIs. Worker threads are ideal for heavy computation, data processing, and parallel workloads—while async I/O remains best handled by the main thread.

Continue

Comprehensive Guide to the Node.js util Module (node:util)

The node:util module provides a powerful collection of helper functions used throughout Node.js core and extremely useful for application developers. These utilities support debugging, inspection, formatting, type checking, callback/Promise conversions, argument parsing, text encoding, MIME handling, and more. It is one of the most versatile and essential toolkits in the Node.js ecosystem.

Continue

Comprehensive Guide to the URL Module in Node.js

The node:url module provides tools for parsing, constructing, and manipulating URLs. Node.js supports two URL APIs: WHATWG URL API — modern, browser‑compatible, standards‑based. Legacy Node.js URL API — older, Node‑specific, now discouraged. The WHATWG API is the recommended approach for all modern applications. It provides a clean, consistent interface for working with URL components, query parameters, and structured URL patterns.

Continue

راهنمای جامع UDP / Datagram Sockets در Node.js

ماژول node:dgram پیاده‌سازی کامل سوکت‌های UDP را در Node.js فراهم می‌کند. UDP یک پروتکل سبک، بدون اتصال (connectionless) و مناسب برای برنامه‌های بلادرنگ مانند VoIP، بازی‌ها، IoT، سیستم‌های پخش (broadcast) و چندپخشی (multicast) است. این ماژول امکان ساخت سوکت، ارسال و دریافت دیتاگرام، مدیریت TTL، عضویت در گروه‌های multicast، کنترل بافرها، و مدیریت رفتار سطح پایین شبکه را فراهم می‌کند.

Continue