Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
port-client
Advanced tools
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.
The Port Client
class offers a killer feature: fast operations.
The 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.
The --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.
When using the --fast
flag or speed: 'fast'
, the script will skip certain checks and perform actions directly on the specified ports.
ports
: The port(s) to operate on (either a number, an array, or a range).options
: Configuration options for the port operation, such as action (check
, kill
), protocol (tcp
or udp
), speed (safe
or fast
), and interactive mode.You 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.
npx port-client 3000
npx port-client 3000 --kill
This 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.
You can enable fast operations in the CLI by using the --fast
flag:
npx port-client 3000 check --fast
This will perform the operation 100 times faster by skipping extra checks.
The 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.
ports
: The port(s) to operate on (either a number, an array, or a range).options
: Configuration options for the port operation. The available options are:
action
: Action to perform on the port(s) (check
, kill
, isExist
). Default is check
.method
: The protocol method to use (tcp
or udp
). Default is tcp
.interactive
: Whether to enable interactive mode for selecting ports. Default is false
.dryRun
: If true
, no actual changes are made (dry run). Default is false
.verbose
: If true
, enables verbose logging. Default is false
.graceful
: If true
, uses graceful termination for killing ports. Default is false
.filter
: A filter for limiting results. Default is null
.range
: A range of ports to check. Default is null
.speed
: The speed mode to use (safe
or fast
). Default is safe
.import port from 'port-client';
const ports = [8080, 3000];
const options = {
action: 'check', // Action to perform
method: 'tcp', // Protocol method
interactive: true, // Enable interactive mode
dryRun: false, // Dry run (no actual changes)
verbose: true, // Enable verbose logging
graceful: true, // Use graceful kill
speed: 'safe', // Safe speed mode (default)
};
const port = new port(ports, options);
port.execute()
.then(() => console.log('Port operations complete.'))
.catch((error) => console.error('Error during port operations:', error));
The 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.
FAQs
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.
The npm package port-client receives a total of 724 weekly downloads. As such, port-client popularity was classified as not popular.
We found that port-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.