npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

port-terminator

v1.0.5

Published

A simple npm package to help you identify and terminate processes using specific ports on your system.

Downloads

40

Readme

Port Terminator

License Version

Port Terminator is an npm library for managing and terminating processes associated with specific ports on your system.

npm install port-terminator
# OR
yarn add port-terminator

Usage

Importing the Library

Import the library in your Node.js application:

const { portTerminator, isPortOpen, portsTerminator } = require("port-terminator");
// or using ES6 import
import { portTerminator, isPortOpen, portsTerminator } from "port-terminator";

Terminating Processes for a Single Port

Use portTerminator to terminate processes associated with a single port:

const portToTerminate = 8080;
try {
  await portTerminator(portToTerminate);
  console.log(`Processes associated with port ${portToTerminate} terminated successfully.`);
} catch (error) {
  console.error(`Error terminating processes for port ${portToTerminate}:`, error);
}

Checking if a Port is Open

Use isPortOpen to check if a port is open:

const portToCheck = 3000;
try {
  const isOpen = await isPortOpen(portToCheck);
  if (isOpen) {
    console.log(`Port ${portToCheck} is open.`);
  } else {
    console.log(`Port ${portToCheck} is closed or invalid.`);
  }
} catch (error) {
  console.error(`Error checking port status for port ${portToCheck}:`, error);
}

Terminating Processes for Multiple Ports

Use portsTerminator to terminate processes associated with multiple ports:

const portsToTerminate = [8080, 3000, 5000];
try {
  const terminationResults = await portsTerminator(...portsToTerminate);
  terminationResults.forEach((response, port) => {
    if (response.status) {
      console.log(`Processes associated with port ${port} terminated successfully.`);
    } else {
      console.error(`Error terminating processes for port ${port}:`, response.error);
    }
  });
} catch (error) {
  console.error("Error terminating processes:", error);
}

Command-Line Interface (CLI)

You can use port-terminator as a global package.

Installation

Install the package globally using npm:

npm install --global port-terminator
# OR
yarn global add port-terminator

Using the CLI

Terminating Processes for a Single Port

To terminate processes associated with a single port, run the following command:

port-terminator 8080

Replace 8080 with the port number you want to terminate processes for.

Terminating Processes for Multiple Ports

You can also terminate processes for multiple ports by specifying multiple port numbers:

port-terminator 9000 3000 5000

Replace 9000, 3000, and 5000 with the port numbers you want to terminate processes for.

Please note that you need administrative or superuser privileges to terminate processes on some systems. Ensure you have the necessary permissions before using this command.

License

This library is open-source and available under the MIT License.