Kill processes running on specified ports. Fast, zero-dependency, cross-platform.
Existing tools like kill-port shell out to lsof -i -P and parse the entire connection table with a loose regex — which means they miss processes, false-match adjacent port numbers, and fail silently on Linux when lsof isn't installed.
zport fixes all of that:
- Linux — uses
fuser(fast, exact match) → falls back toss→ thenlsof - macOS — uses
lsof -tiwith exact port + LISTEN filter - Windows — uses
netstat -anowith exact port + LISTENING match →taskkill - Zero dependencies — just Node.js
child_process.execFile, no shell spawning - TypeScript — fully typed, ships with declarations
npm i -g zportOr run directly without installing:
npx zport 3000
bunx zport 3000# Kill a single port
zport 3000
# Kill multiple ports
zport 3000 3001 8080
# Comma-separated
zport 3000,3001,8080
# UDP instead of TCP
zport 5353 --method udp
zport 5353 -m udpOutput:
✔ :3000 — killed pid 12345
✔ :3001 — killed pids 12346, 12347
✘ :8080 — No process on this port
import { kill } from "zport";
const result = await kill(3000);
// { port: 3000, pids: [12345], killed: true }
const result2 = await kill(9999);
// { port: 9999, pids: [], killed: false, error: "No process on this port" }| Param | Type | Default | Description |
|---|---|---|---|
port |
number |
— | Port number (1–65535) |
method |
"tcp" | "udp" |
"tcp" |
Protocol to match |
Returns Promise<KillResult>:
interface KillResult {
port: number;
pids: number[];
killed: boolean;
error?: string;
}| OS | Find PIDs | Kill |
|---|---|---|
| Linux | fuser {port}/tcp → ss -tlnp → lsof -ti |
SIGKILL |
| macOS | lsof -iTCP:{port} -t -sTCP:LISTEN |
SIGKILL |
| Windows | netstat -ano (exact port + LISTENING) |
taskkill /F |
On Linux, fuser is tried first because it directly queries the kernel's socket table — no parsing, no regex, no false matches. If fuser isn't available (minimal containers), it falls back to ss, then lsof.
MIT