A **Node.js CLI & library** to **detect busy ports** and **terminate processes by port number**.
npm install port-fix-cliA Node.js CLI & library to detect busy ports and terminate processes by port number.
Designed for real-world development environments, port-fix-cli prioritizes correctness, transparency, and safety over shortcuts.
---
- π οΈ port-fix-cli
- π Table of Contents
- β¨ Features
- π₯οΈ Platform Support
- Linux β
(Recommended)
- Windows β οΈ
- macOS β οΈ
- π¦ Installation
- Global installation (recommended for CLI usage)
- Local / one-time usage
- π Usage
- CLI
- List all busy ports
- Kill the process running on a specific port
- Linux + sudo (important)
- π¦ Using as a Module
- π§ How it works
- Busy port detection
- Process detection
- π§βπ» Developer Note: Port killed but still appears busy
- Why this happens
- β οΈ Limitations \& Notes
- π Sudo + nvm Note (Linux)
- π¬ Feedback, Issues \& Discussions
- πΊοΈ Roadmap (Planned)
- π License
- β¨ Author
---
* π Safely scan and list busy ports (no OS overload)
* πͺ Kill processes running on a specific port
* π§ Intelligent PID detection
* Node.js process lookup
* Linux OS-level socket inspection fallback (ss)
* π» Works across Linux, macOS, and Windows
(Linux has the most complete support)
* π§± Usable as:
* a global CLI tool
* a local CLI via npx
* a Node.js module
---
* Full support
* Handles sudo
* OS-level PID detection
* Threaded runtimes (MainThread)
* Docker & IPv6 edge cases
* TCP TIME_WAIT awareness
* Supported for common development use cases
* Works well with npx
* Handles typical Node.js / React / local servers
* OS-level fallback (netstat + taskkill) planned
* Supported for common development use cases
* Uses Node.js process detection
* OS-level fallback (lsof) planned
---
``bash`
npm install -g port-fix-cli
π‘ Linux note
`bash`
sudo npm install -g port-fix-cli
---
`bash`
npx port-fix-cli --list
β οΈ Important
npx cannot be used with sudo on systems where Node.js is installed using nvm.
---
#### List all busy ports
`bash`
port-check --list
#### Kill the process running on a specific port
`bash`
port-check --kill 3000
---
`bash`
sudo env "PATH=$PATH" port-check --kill 3000
Required when:
* Node.js is installed via nvm
* The process is not owned by your user
* The port is bound by a system-level service
---
`js
const { listBusyPorts, killPort } = require("port-fix-cli");
(async () => {
await listBusyPorts([3000, 3010]);
await killPort(3000);
})();
`
---
Ports are checked safely by attempting a temporary bind, avoiding massive parallel socket creation.
1. Tries Node.js process lookup
2. Falls back to Linux OS socket inspection (ss)
* Detects MainThread
* Detects Docker proxy ports
* Detects IPv6 listeners
---
`bash
sudo env "PATH=$PATH" port-check --kill 3000
πͺ Killed PID 51918 on port 3000
sudo env "PATH=$PATH" port-check --kill 3000
β οΈ Port 3000 is busy but no killable PID found.
`
After a process is terminated, the OS may keep the TCP socket in TIME_WAIT state.
* The port may appear busy
* No process owns the port
* There is no PID to kill
* The kernel is safely cleaning up the socket
Verify manually (Linux):
`bash`
sudo ss -tan | grep :3000
---
A port may appear busy but not killable if:
* It is exposed by Docker
* It is managed by systemd or OS servicesTIME_WAIT
* It requires elevated permissions
* The socket is in
port-fix-cli reports this honestly instead of failing silently.
---
If Node.js is installed using nvm, sudo will not detect node automatically.
`bash`
sudo env "PATH=$PATH" port-check --kill
This is expected Linux behavior.
---
This project is actively evolving, and feedback is very welcome π
* π Bug reports
* π‘ Feature ideas
* π₯οΈ OS-specific edge cases
* π£ Documentation improvements
π Open an issue here:
https://github.com/sachinabs/port-fix-cli/issues
Iβm happy to discuss design decisions, edge cases, and improvements with fellow developers.
---
* Windows OS-level fallback (netstat + taskkill)lsof
* macOS fallback ()port-check doctor
* commandTIME_WAIT` detection
* Improved UX for
---
MIT License
---
Created with β€οΈ by
Anish Bala Sachin
π https://github.com/sachinabs