killport-npm
v2.0.2
Published
CLI to find the process listening on a TCP port and terminate it. Works on Windows, macOS, Linux, and WSL.
Maintainers
Readme
killport-npm
CLI that finds the process listening on a TCP port and terminates it. Works on Windows, macOS, Ubuntu / Linux, and WSL (same code path as Linux).
Table of contents
- Requirements
- Install (quick reference)
- Install on Windows
- Install on macOS
- Install on Ubuntu (and most Debian-based Linux)
- Install on WSL (Windows Subsystem for Linux)
- How to use (proper workflow)
- Usage summary
- Package lifecycle (npm / pnpm / yarn)
- Authors
Requirements
- Node.js 18+ (from nodejs.org, your OS package manager, or a version manager such as nvm / fnm / n)
Package managers supported:
- npm (ships with Node)
- pnpm — same package; lifecycle scripts (
preinstall/postinstall) run the same as with npm - Yarn — same package; use Yarn Classic (1.x)
yarn global addfor a global CLI, oryarn dlx(Yarn 2+) for a one-off run (same idea asnpx/pnpm dlx)
Platform tools used:
| OS | Resolution | Kill |
|----|------------|------|
| macOS | lsof | kill |
| Linux / WSL | ss, then lsof | kill |
| Windows | netstat | taskkill |
Killing processes owned by another user may require Administrator (Windows) or sudo (Unix).
Install (quick reference)
| Goal | npm | pnpm | Yarn |
|------|-----|------|------|
| Global CLI (killport on your PATH) | npm install -g killport-npm | pnpm add -g killport-npm | yarn global add killport-npm (Classic 1.x only; ensure Yarn global bin is on PATH) |
| One-off, no global install | npx killport-npm <port> | pnpm dlx killport-npm <port> | yarn dlx killport-npm <port> (Yarn 2+; for Yarn 1 use npx or a global install) |
After a global install, run:
killport --help
killport 3000If killport is not found, your global bin directory is not on PATH. See the OS sections below.
Install on Windows
Install Node.js 18+
- Download from nodejs.org, or e.g.
winget install OpenJS.NodeJS.LTS(build may vary).
- Download from nodejs.org, or e.g.
Optional: install pnpm
- Follow pnpm installation (e.g.
npm install -g pnpmor the standalone script).
- Follow pnpm installation (e.g.
Install this package globally
npm install -g killport-npmor
pnpm add -g killport-npmor (Yarn Classic 1.x)
yarn global add killport-npmPATH
- npm: global binaries usually live under
%AppData%\npm. The Node installer often adds this to PATH. - pnpm: run
pnpm setuponce and follow the printed instructions so the pnpm global bin is on PATH. - Yarn Classic: run
yarn global binand add that folder to PATH ifkillportis not found. - Open a new terminal after changing PATH.
- npm: global binaries usually live under
Permissions
- If
taskkillfails for a system or other user’s process, open PowerShell or Command Prompt as Administrator and runkillport <port>again.
- If
Use without global install
npx killport-npm 3000 pnpm dlx killport-npm 3000 yarn dlx killport-npm 3000
Install on macOS
Install Node.js 18+ (official installer, Homebrew
brew install node, or nvm/fnm).Install globally
npm install -g killport-npm # or pnpm add -g killport-npm # or (Yarn Classic 1.x) yarn global add killport-npmPATH
- If
killportis not found, ensure your npm global prefix is on PATH (npm prefix -g→binnext to it). For pnpm, runpnpm setupif you use pnpm’s default store layout. For Yarn Classic, add Yarn’s global bin to PATH (seeyarn global bin).
- If
Permissions
- If you get permission errors killing another user’s process, use
sudo killport <port>(only when necessary).
- If you get permission errors killing another user’s process, use
One-off
npx killport-npm 3000 pnpm dlx killport-npm 3000 yarn dlx killport-npm 3000
lsof is available by default on macOS.
Install on Ubuntu (and most Debian-based Linux)
Install Node.js 18+
- e.g. NodeSource, nvm, or your distro’s packages if the version is ≥ 18.
Tools
ssis iniproute2(usually preinstalled):sudo apt update && sudo apt install -y iproute2- Optional fallback:
sudo apt install -y lsof
Install globally
npm install -g killport-npm # or pnpm add -g killport-npm # or (Yarn Classic 1.x) yarn global add killport-npmPATH
- Same idea as macOS: ensure the global
bindirectory npm/pnpm/Yarn uses is on yourPATH(restart the shell after changes).
- Same idea as macOS: ensure the global
Permissions
- Use
sudo killport <port>if the listener is owned by root or another user.
- Use
One-off
npx killport-npm 3000 pnpm dlx killport-npm 3000 yarn dlx killport-npm 3000
Install on WSL (Windows Subsystem for Linux)
WSL runs a Linux distro; install Node inside that distro (not only on Windows), then use the same commands as Ubuntu / Linux above.
Open your WSL terminal (e.g. Ubuntu).
Install Node 18+ there (nvm is a common choice).
Run:
npm install -g killport-npm # or pnpm add -g killport-npm # or (Yarn Classic 1.x) yarn global add killport-npm
Important: killport in WSL only sees processes in that Linux environment. If a server is bound on the Windows host, kill it from Windows (PowerShell/CMD) with a Windows install of Node + killport, or stop the process from Task Manager.
Ensure iproute2 / ss (and optionally lsof) are installed in the distro, as on Ubuntu.
How to use (proper workflow)
See what would be killed (safe):
killport 3000 --dry-runKill the listener (default is forceful:
SIGKILLon Unix,taskkill /Fon Windows):killport 3000Try graceful shutdown first (then force on Unix if needed; on Windows tries
taskkillwithout/F, then/F):killport 3000 --gracefulInteractive mode (only when stdin is a TTY): run
killportwith no arguments and enter the port when prompted.Help:
killport --help
Usage summary
killport <port> [options]| Option | Meaning |
|--------|---------|
| --dry-run | Print PID(s) that would be killed; do not kill |
| --graceful | SIGTERM / taskkill without /F first (Unix then SIGKILL if needed) |
| --help, -h | Help |
Same flags work with runners, for example:
npx killport-npm 8080 --dry-run
pnpm dlx killport-npm 8080 --dry-run
yarn dlx killport-npm 8080 --dry-runPackage lifecycle (npm / pnpm / yarn)
preinstall and postinstall run for npm, pnpm, and yarn installs of this package.
| Script | When | Purpose |
|--------|------|---------|
| preinstall | Before install | Ensures Node ≥ 18 |
| postinstall | After install | Short usage hint (WSL hint when detected) |
| prepublishOnly | Before npm publish | Syntax-checks CLI and lib files (maintainers) |
