Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/pid-port
Get the ID of the process that uses a certain port
https://github.com/sindresorhus/pid-port
Last synced: about 1 month ago
JSON representation
Get the ID of the process that uses a certain port
- Host: GitHub
- URL: https://github.com/sindresorhus/pid-port
- Owner: sindresorhus
- License: mit
- Created: 2020-12-27T10:34:28.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-11-04T15:03:53.000Z (about 1 year ago)
- Last Synced: 2024-04-14T11:09:15.495Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 20.5 KB
- Stars: 137
- Watchers: 6
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# pid-port
> Get the ID of the process that uses a certain port
## Install
```sh
npm install pid-port
```## Usage
```js
import {portToPid} from 'pid-port';try {
console.log(await portToPid(8080));
//=> 1337const pids = await portToPid([8080, 22]);
console.log(pids.get(8080));
//=> 1337console.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` *(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>` *(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>` with the ports.
#### pid
Type: `number`
The process ID to look up.
### pidToPorts(pids)
Get the ports for multiple process IDs.
Returns a `Promise>>` 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>` *(integer)* with the port as key and the process ID as value.
## Related
- [fkill-cli](https://github.com/sindresorhus/fkill-cli) - Uses this package to let you kill the process that occupies a certain port
- [pid-cwd](https://github.com/neeksandhu/pid-cwd) - Find the working directory of a process from its process ID