{"library":"node-netstat","title":"Node.js Netstat Utility","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install node-netstat"],"cli":null},"imports":["const netstat = require('node-netstat');","const netstat = require('node-netstat');\nnetstat.parsers.linux = netstat.parserFactories.linux({ parseName: true });","const netstat = require('node-netstat');\nconsole.log(netstat.version);"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const netstat = require('node-netstat');\n\n// Get network connections, filtering by a specific PID and protocol,\n// limiting the results to the first 5 entries.\nnetstat({\n  filter: {\n    pid: process.env.TARGET_PID ? parseInt(process.env.TARGET_PID) : 1, // Example PID, adjust as needed\n    protocol: 'tcp'\n  },\n  limit: 5,\n  done: (err) => {\n    if (err) {\n      console.error('Netstat command failed:', err);\n      return;\n    }\n    console.log('Netstat command completed.');\n  }\n}, function (data) {\n  // Process each line of netstat data\n  console.log('Netstat item:', data);\n\n  // Example: stop processing after finding a specific state\n  if (data.state === 'ESTABLISHED') {\n    console.log('Found an ESTABLISHED connection, stopping further processing.');\n    return false; // Returning false stops the stream\n  }\n});","lang":"javascript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}