node-netstat is a JavaScript utility library designed to programmatically read and parse `netstat` data on various operating systems. It is currently at version 1.9.0 and provides a callback-based API for processing network connection information line by line. The library supports filtering results by properties like PID or protocol and offers both synchronous and asynchronous execution. Key differentiators include its cross-platform compatibility (tested on Ubuntu 14.04/16.04, Windows 7, and OS X Yosemite), extensibility via custom parsers and filters, and the ability to cancel ongoing `watch` operations. While `netstat` itself is considered obsolete on some Linux systems in favor of `ss`, node-netstat provides a unified interface for accessing this data where available, making it suitable for system monitoring and debugging tools in Node.js environments.
npm install node-netstatVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `node-netstat` to asynchronously retrieve and filter network connection data. It shows how to apply filters for PID and protocol, limit the output, handle errors with the `done` callback, and conditionally stop processing results early from within the line handler function.
Set `parseName: true` when initializing the Linux parser factory for `netstat.parsers.linux` to include process names in the output.
Ensure your `handler` function only returns `false` when you explicitly want to stop processing the stream of netstat results. Otherwise, omit an explicit return or return `true`.
Verify that the `netstat` utility is available and correctly installed on the target system. For new projects or critical applications, consider alternatives that use newer tools like `ss` or `procfs` for network statistics if `node-netstat` encounters issues on a specific OS version.
Store the return value of `netstat()` when using `watch: true`. Call `handler.cancel()` to stop the watching process when it's no longer required, typically in cleanup routines or when the application is shutting down.
Install the `net-tools` package on Linux (e.g., `sudo apt-get install net-tools` or `sudo yum install net-tools`) or ensure the `netstat` executable's directory is included in the system's PATH environment variable on Windows or other OS. Alternatively, verify if the `platform` option is correctly set if overriding `os.platform()`.
Check the `node-netstat` GitHub issues for known compatibility problems with your specific OS version. If no solution is available, consider contributing a fix or using a different system monitoring tool. Temporary workarounds might involve adjusting `filter` options or inspecting the raw `netstat` output to identify parsing discrepancies.
No dependency data recorded yet.