{"id":25238084,"url":"https://github.com/fix2015/port-client","last_synced_at":"2025-04-07T05:14:42.549Z","repository":{"id":267022234,"uuid":"899930571","full_name":"fix2015/port-client","owner":"fix2015","description":"A powerful utility for managing processes on specified ports, including options for checking port status, killing processes, handling multiple ports, enabling interactive mode, and supporting graceful termination.","archived":false,"fork":false,"pushed_at":"2025-02-02T21:27:36.000Z","size":812,"stargazers_count":100,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-31T04:06:52.540Z","etag":null,"topics":["cli","development-tool","interactive-cli","javascript","nodejs","port","port-client","port-manager","process-termination","tcp","udp","webpack"],"latest_commit_sha":null,"homepage":"https://medium.com/@vitaliisemianchuk/building-portclient-a-tool-to-simplify-and-speed-up-port-management-edce11f35b4b","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fix2015.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-07T12:08:08.000Z","updated_at":"2025-03-21T23:11:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"784e81bf-bca5-4e15-a256-7b33c8ceeaed","html_url":"https://github.com/fix2015/port-client","commit_stats":null,"previous_names":["fix2015/clean-port"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fix2015%2Fport-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fix2015%2Fport-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fix2015%2Fport-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fix2015%2Fport-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fix2015","download_url":"https://codeload.github.com/fix2015/port-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247595335,"owners_count":20963943,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","development-tool","interactive-cli","javascript","nodejs","port","port-client","port-manager","process-termination","tcp","udp","webpack"],"created_at":"2025-02-11T16:43:44.332Z","updated_at":"2025-04-07T05:14:42.529Z","avatar_url":"https://github.com/fix2015.png","language":"JavaScript","readme":"![alt text](image.png)\n# Port Client\n\nThe `Port Client` class offers a **killer feature**: **fast operations**. \n\n## Table of Contents\n\n1. [Overview](#overview)\n2. [Command-Line Interface (CLI) Usage](#cli-usage)\n3. [Class Constructor](#class-constructor)\n4. [Usage Example](#usage-example)\n\n## Overview\n\nThe `Port Client` class allows users to interact with network ports, providing functionalities to check whether a port is active, kill a port, and verify the existence of ports. It supports both **TCP** and **UDP** protocols, works on multiple platforms (Windows and Unix-like systems), and includes a `dryRun` mode for testing.\n\n### Key Feature: **Fast Operations**\n\nThe `--fast` flag for the CLI or the `speed: 'fast'` option for the script provides **fast operations**. This option makes port operations significantly faster by bypassing slower checks like listing all active ports. It's particularly useful when you need to check or kill ports quickly.\n\nWhen using the `--fast` flag or `speed: 'fast'`, the script will skip certain checks and perform actions directly on the specified ports.\n\n### Parameters:\n\n- `ports`: The port(s) to operate on (either a number, an array, or a range).\n- `options`: Configuration options for the port operation, such as action (`check`, `kill`), protocol (`tcp` or `udp`), speed (`safe` or `fast`), and interactive mode.\n\n## Command-Line Interface (CLI) Usage\n\nYou can also use the `Port Client` class via a command-line interface by calling it from a `cli.js` script. This allows you to interact with the ports directly from your terminal.\n\n### Running the CLI\n\n1. **To check port(s)**:\n\n```\nnpx port-client 3000\n```\n\n2. **To kill a port(s)**:\n\n```\nnpx port-client 3000 --kill\n```\n\nThis script accepts a list of ports followed by an action (`check` or `kill`). The ports will be parsed, and the specified action will be executed.\n\n### Fast Operation Flag\n\nYou can enable **fast operations** in the CLI by using the `--fast` flag:\n\n```\nnpx port-client 3000 check --fast\n```\n\nThis will perform the operation 100 times faster by skipping extra checks.\n\n## Class Constructor\n\nThe constructor of the `Port Client` class initializes an instance with the ports and options for the port operation. Below are the parameters available for the constructor.\n\n### Constructor Parameters:\n- `ports`: The port(s) to operate on (either a number, an array, or a range).\n- `options`: Configuration options for the port operation. The available options are:\n  - `action`: Action to perform on the port(s) (`check`, `kill`, `isExist`). Default is `check`.\n  - `method`: The protocol method to use (`tcp` or `udp`). Default is `tcp`.\n  - `interactive`: Whether to enable interactive mode for selecting ports. Default is `false`.\n  - `dryRun`: If `true`, no actual changes are made (dry run). Default is `false`.\n  - `verbose`: If `true`, enables verbose logging. Default is `false`.\n  - `graceful`: If `true`, uses graceful termination for killing ports. Default is `false`.\n  - `filter`: A filter for limiting results. Default is `null`.\n  - `range`: A range of ports to check. Default is `null`.\n  - `speed`: The speed mode to use (`safe` or `fast`). Default is `safe`.\n\n### Example Usage:\n```js\nimport port from 'port-client';\n\nconst ports = [8080, 3000];\nconst options = {\n  action: 'check',         // Action to perform\n  method: 'tcp',           // Protocol method\n  interactive: true,       // Enable interactive mode\n  dryRun: false,           // Dry run (no actual changes)\n  verbose: true,           // Enable verbose logging\n  graceful: true,          // Use graceful kill\n  speed: 'safe',           // Safe speed mode (default)\n};\n\nconst port = new port(ports, options);\nport.execute()\n  .then(() =\u003e console.log('Port operations complete.'))\n  .catch((error) =\u003e console.error('Error during port operations:', error));\n```\n\n## Conclusion\n\nThe `Port Client` class offers a flexible and interactive way to manage ports, whether you're checking if they're active, killing processes associated with them, or performing dry runs to preview actions. It can be used in a Node.js script or directly in the shell using the provided CLI script.\n\n## Connect with Me:\n- [LinkedIn - Vitalii Semianchuk](https://www.linkedin.com/in/vitalii-semianchuk-9812a786/)\n- [Telegram - @jsmentorfree](https://t.me/jsmentorfree) - We do a lot of free teaching on this channel! Join us to learn and grow in web development.\n- [Tiktok - @jsmentoring](https://www.tiktok.com/@jsmentoring) Everyday new videos\n- [Youtube - @jsmentor-uk](https://www.youtube.com/@jsmentor-uk) Mentor live streams\n- [Dev.to - fix2015](https://dev.to/fix2015) Javascript featured, live, experience\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffix2015%2Fport-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffix2015%2Fport-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffix2015%2Fport-client/lists"}