Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hilleer/kill-port-process
Kill long running process(es) on port(s) programatically or with the CLI
https://github.com/hilleer/kill-port-process
kill-port kill-port-process kill-process node
Last synced: 2 days ago
JSON representation
Kill long running process(es) on port(s) programatically or with the CLI
- Host: GitHub
- URL: https://github.com/hilleer/kill-port-process
- Owner: hilleer
- License: mit
- Created: 2018-11-03T15:05:15.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2025-02-04T12:49:59.000Z (10 days ago)
- Last Synced: 2025-02-05T07:08:05.823Z (10 days ago)
- Topics: kill-port, kill-port-process, kill-process, node
- Language: TypeScript
- Homepage:
- Size: 492 KB
- Stars: 28
- Watchers: 1
- Forks: 5
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
- awesome-tools - **kill-port-process** - 命令行杀死被占用的端口服务 `kill-port 3000` (脚手架以及工具包)
README
# Kill-port-process
[![npm version](https://badge.fury.io/js/kill-port-process.svg)](https://badge.fury.io/js/kill-port-process)
[![Test](https://github.com/hilleer/kill-port-process/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/hilleer/kill-port-process/actions/workflows/ci.yml)
[![CodeQL](https://github.com/hilleer/kill-port-process/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/hilleer/kill-port-process/actions/workflows/github-code-scanning/codeql)**Cross-platform** module to stop one (or more) process(es) running on a port (or a list of ports).
## Install
```bash
$ npm install kill-port-process
# or
$ yarn add kill-port-process
```## Usage
### Programmatically
```javascript
const { killPortProcess } = require('kill-port-process');(async () => {
// long running process running on a given port(s), e.g. a http-server
// takes a number, number[], string or string[]
// single port
await killPortProcess(1234);// multiple ports
await killPortProcess([1234, 6789]);// with options
await killPortProcess(1234, { signal: 'SIGTERM' });
})();
```#### Options
* `signal` (optional): used to determine the command used to kill the provided port(s). Valid values are:
* `SIGKILL` (default)
* `SIGTERM`### CLI
Install the module globally:
```bash
npm install kill-port-process -g
```You can use the CLI calling it with `kill-port `.
It takes a single port or a list of ports separated by a space. Valid flags are `-p` and `--port` but are both optional.
```bash
$ kill-port 1234
# or multiple ports, separated by space(s)
$ kill-port 1234 2345
# or
$ kill-port -p 1234
# or
$ kill-port --port 1234
```#### Flags
* `--graceful` kill the process gracefully.
* **Unix:** Sends a `-15` signal to kill (`SIGTERM`) rather than `-9` (`SIGKILL`)
* **Win:** Currently no use## Compatibility
Compiled for [es5](https://compat-table.github.io/compat-table/es5) and supported by node v16 and onwards.
---
[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/hilleer)