Skip to content

itorz7/zport

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zport

Kill processes running on specified ports. Fast, zero-dependency, cross-platform.

Why zport?

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 to ss → then lsof
  • macOS — uses lsof -ti with exact port + LISTEN filter
  • Windows — uses netstat -ano with exact port + LISTENING match → taskkill
  • Zero dependencies — just Node.js child_process.execFile, no shell spawning
  • TypeScript — fully typed, ships with declarations

Install

npm i -g zport

Or run directly without installing:

npx zport 3000
bunx zport 3000

Usage

CLI

# 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 udp

Output:

✔ :3000 — killed pid 12345
✔ :3001 — killed pids 12346, 12347
✘ :8080 — No process on this port

Programmatic

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" }

kill(port, method?)

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;
}

How it works

OS Find PIDs Kill
Linux fuser {port}/tcpss -tlnplsof -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.

License

MIT

About

Kill processes running on specified ports. Fast, zero-dependency, cross-platform.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors