Coder Social home page Coder Social logo

pid-port's Introduction

pid-port

Get the ID of the process that uses a certain port

Install

npm install pid-port

Usage

import {portToPid} from 'pid-port';

try {
	console.log(await portToPid(8080));
	//=> 1337

	const pids = await portToPid([8080, 22]);

	console.log(pids.get(8080));
	//=> 1337

	console.log(pids.get(22));
	//=> 12345
} catch (error) {
	console.log(error);
	//=> 'Could not find a process that uses port `8080`'
}

API

portToPid(port)

Get the process ID for a port.

Returns a Promise<number | undefined> (integer) with the process ID.

port

Type: number (integer)

The port to look up.

portToPid(ports)

Get the process IDs for multiple ports.

Returns a Promise<Map<number, number>> (integer) with the port as key and the process ID as value.

ports

Type: number[] (integer)

The ports to look up.

pidToPorts(pid)

Get the ports for a process ID.

Returns a Promise<Set<number>> with the ports.

pid

Type: number

The process ID to look up.

pidToPorts(pids)

Get the ports for multiple process IDs.

Returns a Promise<Map<number, Set<number>>> with the process ID as the key and the ports as value.

pids

Type: number[]

The process IDs to look up.

allPortsWithPid()

Get all ports with their process ID.

Returns a Promise<Map<number, number>> (integer) with the port as key and the process ID as value.

Related

  • fkill-cli - Uses this package to let you kill the process that occupies a certain port
  • pid-cwd - Find the working directory of a process from its process ID

pid-port's People

Contributors

richienb avatar sindresorhus avatar zikaari avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pid-port's Issues

`host` option

> require("net").createServer().listen("1234", "127.0.0.1")
> require("net").createServer().listen("1234", "127.0.0.2")
$ ss | grep 1234
LISTEN   0        0                127.0.0.2:1234             0.0.0.0:*       users:(("node",pid=1561254,fd=22))
LISTEN   0        0                127.0.0.1:1234             0.0.0.0:*       users:(("node",pid=1561255,fd=21))

A host option is needed to distinguish. Could accept the same signatures as net.Server#listen.

Add `pid-cwd` to related section

I'm the author of pid-cwd, a cross-platform library to find the directory where a process was started.

I think if these packages are cross-referenced, it will enhance the process for people building things like ultra-runner (uses pid-cwd to show Project column)

You can close the issue to reject.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.