A 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
- π¦ Installation
- π Usage
- π¦ Using as a Module
- π§ How it works
- π§βπ» Developer Note: Port killed but still appears busy
β οΈ 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_WAITawareness
- 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
npm install -g port-fix-cliπ‘ Linux note
sudo npm install -g port-fix-clinpx port-fix-cli --listnpx cannot be used with sudo on systems where Node.js is installed using nvm.
port-check --listport-check --kill 3000sudo env "PATH=$PATH" port-check --kill 3000Required when:
- Node.js is installed via
nvm - The process is not owned by your user
- The port is bound by a system-level service
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.
-
Tries Node.js process lookup
-
Falls back to Linux OS socket inspection (
ss)- Detects
MainThread - Detects Docker proxy ports
- Detects IPv6 listeners
- Detects
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):
sudo ss -tan | grep :3000A port may appear busy but not killable if:
- It is exposed by Docker
- It is managed by
systemdor OS services - It requires elevated permissions
- The socket is in
TIME_WAIT
port-fix-cli reports this honestly instead of failing silently.
If Node.js is installed using nvm, sudo will not detect node automatically.
sudo env "PATH=$PATH" port-check --kill <port>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) - macOS fallback (
lsof) port-check doctorcommand- Improved UX for
TIME_WAITdetection
MIT License
Created with β€οΈ by Anish Bala Sachin π https://github.com/sachinabs