portcleaner 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +306 -0
- package/bin/cleanports.js +69 -0
- package/package.json +20 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shubhashish Chakraborty
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
# π§Ή Clean Ports (cleanports CLI)
|
|
2
|
+
|
|
3
|
+
Instantly kill stuck development servers and free your ports.
|
|
4
|
+
|
|
5
|
+
`cleanports` is a lightweight CLI tool that scans your system for running development servers (Node, Bun, Deno, Python, Docker proxies, etc.) and automatically releases the ports they are occupying.
|
|
6
|
+
|
|
7
|
+
No more:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
EADDRINUSE: address already in use :::3000
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## π Table of Contents
|
|
16
|
+
|
|
17
|
+
* [Why this exists](#why-this-exists)
|
|
18
|
+
* [Features](#features)
|
|
19
|
+
* [Supported Platforms](#supported-platforms)
|
|
20
|
+
* [Quick Install (Automatic - Recommended)](#quick-install-automatic-recommended)
|
|
21
|
+
* [Manual Installation (Local Development)](#manual-installation-local-development)
|
|
22
|
+
* [Usage](#usage)
|
|
23
|
+
* [Add to your project workflow](#add-to-your-project-workflow)
|
|
24
|
+
* [Uninstall / Disable cleanports](#uninstall--disable-cleanports)
|
|
25
|
+
* [Re-enable later](#re-enable-later)
|
|
26
|
+
* [Requirements](#requirements)
|
|
27
|
+
* [How it works](#how-it-works)
|
|
28
|
+
* [Troubleshooting](#troubleshooting)
|
|
29
|
+
* [Contributing](#contributing)
|
|
30
|
+
* [License](#license)
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Why this exists
|
|
35
|
+
|
|
36
|
+
During development, servers often **do not shut down properly**:
|
|
37
|
+
|
|
38
|
+
* Next.js / React dev servers
|
|
39
|
+
* Express / Fastify APIs
|
|
40
|
+
* Prisma / WebSocket servers
|
|
41
|
+
* Docker containers
|
|
42
|
+
* AI coding agents
|
|
43
|
+
|
|
44
|
+
Even after closing the terminal, the process continues running in the background and blocks ports.
|
|
45
|
+
|
|
46
|
+
Developers repeatedly run:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
lsof -i :3000
|
|
50
|
+
kill -9 <PID>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
This tool automates that entire process.
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## β¨ Features
|
|
58
|
+
|
|
59
|
+
* Detects active listening ports
|
|
60
|
+
* Finds development servers automatically
|
|
61
|
+
* Safely terminates only dev processes
|
|
62
|
+
* Does NOT affect OS system services
|
|
63
|
+
* Works globally from any directory
|
|
64
|
+
* One-command cleanup
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## π» Supported Platforms
|
|
69
|
+
|
|
70
|
+
| OS | Support |
|
|
71
|
+
| ---------------------------------- | -------------- |
|
|
72
|
+
| macOS | β
Full support |
|
|
73
|
+
| Linux (Ubuntu, Debian, Arch, etc.) | β
Full support |
|
|
74
|
+
| Windows (WSL) | β
Supported |
|
|
75
|
+
| Windows (PowerShell / CMD native) | β οΈ Limited |
|
|
76
|
+
|
|
77
|
+
### Important for Windows users
|
|
78
|
+
|
|
79
|
+
Windows does not include the `lsof` utility.
|
|
80
|
+
Please run this tool inside:
|
|
81
|
+
|
|
82
|
+
* WSL (recommended)
|
|
83
|
+
* Git Bash
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## π Quick Install (Automatic β Recommended)
|
|
88
|
+
|
|
89
|
+
This is the **normal user method**.
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
npm install -g clean-ports
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
After installation, simply run:
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
cleanports
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Thatβs it. No linking. No configuration.
|
|
102
|
+
|
|
103
|
+
The installer automatically:
|
|
104
|
+
|
|
105
|
+
* registers the CLI command
|
|
106
|
+
* grants permissions
|
|
107
|
+
* verifies environment
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## π Manual Installation (Local Development)
|
|
112
|
+
|
|
113
|
+
Use this if you cloned the repository.
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
git clone https://github.com/<your-username>/clean-ports.git
|
|
117
|
+
cd clean-ports
|
|
118
|
+
npm install
|
|
119
|
+
npm link
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Now the command works globally:
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
cleanports
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## βΆοΈ Usage
|
|
131
|
+
|
|
132
|
+
Run:
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
cleanports
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Example output:
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
π Scanning for running dev servers...
|
|
142
|
+
|
|
143
|
+
β οΈ Found running servers:
|
|
144
|
+
|
|
145
|
+
β’ node running on port 3000 (PID 5542)
|
|
146
|
+
β’ docker-proxy running on port 5432 (PID 8821)
|
|
147
|
+
|
|
148
|
+
π§Ή Cleaning ports...
|
|
149
|
+
|
|
150
|
+
β Killed node on port 3000
|
|
151
|
+
β Killed docker-proxy on port 5432
|
|
152
|
+
|
|
153
|
+
π All development ports cleaned!
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## π Add to your project workflow
|
|
159
|
+
|
|
160
|
+
You can automatically clean ports before starting your app.
|
|
161
|
+
|
|
162
|
+
Add inside any project's `package.json`:
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
"scripts": {
|
|
166
|
+
"dev": "cleanports && npm run start"
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
or for Next.js:
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
"dev": "cleanports && next dev"
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Now every time your project starts β ports are cleaned first.
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## β Uninstall / Disable cleanports
|
|
181
|
+
|
|
182
|
+
If you no longer want the `cleanports` command on your system:
|
|
183
|
+
|
|
184
|
+
### If installed globally (recommended install)
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
npm uninstall -g clean-ports
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### If installed via `npm link`
|
|
191
|
+
|
|
192
|
+
Inside the project folder:
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
npm unlink -g clean-ports
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
After uninstalling, running:
|
|
199
|
+
|
|
200
|
+
```
|
|
201
|
+
cleanports
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
will no longer work.
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## π Re-enable later
|
|
209
|
+
|
|
210
|
+
You can always reinstall:
|
|
211
|
+
|
|
212
|
+
```
|
|
213
|
+
npm install -g clean-ports
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
The command will immediately start working again.
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## π¦ Requirements
|
|
221
|
+
|
|
222
|
+
* Node.js v16 or newer
|
|
223
|
+
* macOS or Linux (native support)
|
|
224
|
+
* Windows requires WSL or Git Bash
|
|
225
|
+
|
|
226
|
+
Check Node version:
|
|
227
|
+
|
|
228
|
+
```
|
|
229
|
+
node -v
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## βοΈ How it works
|
|
235
|
+
|
|
236
|
+
The CLI internally runs:
|
|
237
|
+
|
|
238
|
+
```
|
|
239
|
+
lsof -i -P -n | grep LISTEN
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
It filters only known development processes:
|
|
243
|
+
|
|
244
|
+
* node
|
|
245
|
+
* bun
|
|
246
|
+
* deno
|
|
247
|
+
* python
|
|
248
|
+
* docker
|
|
249
|
+
* docker-proxy
|
|
250
|
+
|
|
251
|
+
Then safely terminates them using system signals.
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## π§― Troubleshooting
|
|
256
|
+
|
|
257
|
+
### `cleanports: command not found`
|
|
258
|
+
|
|
259
|
+
Restart terminal or run:
|
|
260
|
+
|
|
261
|
+
```
|
|
262
|
+
source ~/.zshrc
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
### Permission denied
|
|
268
|
+
|
|
269
|
+
```
|
|
270
|
+
chmod +x bin/cleanports.js
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
### Nothing was killed
|
|
276
|
+
|
|
277
|
+
Verify something is actually using a port:
|
|
278
|
+
|
|
279
|
+
```
|
|
280
|
+
lsof -i :3000
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## π€ Contributing
|
|
286
|
+
|
|
287
|
+
Pull requests are welcome.
|
|
288
|
+
|
|
289
|
+
Possible improvements:
|
|
290
|
+
|
|
291
|
+
* interactive confirmation mode
|
|
292
|
+
* port range filtering
|
|
293
|
+
* Windows native support
|
|
294
|
+
* database port exclusions (5432, 27017)
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## π License
|
|
299
|
+
|
|
300
|
+
MIT
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## π¨βπ» Author
|
|
305
|
+
|
|
306
|
+
Shubhashish Chakraborty
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { execSync } = require("child_process");
|
|
4
|
+
|
|
5
|
+
console.log("π Scanning for running dev servers...\n");
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
const output = execSync("lsof -i -P -n | grep LISTEN", {
|
|
9
|
+
encoding: "utf8",
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const lines = output.split("\n");
|
|
13
|
+
|
|
14
|
+
const targets = [];
|
|
15
|
+
|
|
16
|
+
lines.forEach((line) => {
|
|
17
|
+
if (!line.trim()) return;
|
|
18
|
+
|
|
19
|
+
const parts = line.trim().split(/\s+/);
|
|
20
|
+
const command = parts[0];
|
|
21
|
+
const pid = parts[1];
|
|
22
|
+
const portMatch = line.match(/:(\d+)\s/);
|
|
23
|
+
|
|
24
|
+
if (!portMatch) return;
|
|
25
|
+
const port = portMatch[1];
|
|
26
|
+
|
|
27
|
+
// Only kill development servers
|
|
28
|
+
const allowedProcesses = [
|
|
29
|
+
"node",
|
|
30
|
+
"bun",
|
|
31
|
+
"deno",
|
|
32
|
+
"docker",
|
|
33
|
+
"docker-proxy",
|
|
34
|
+
"python",
|
|
35
|
+
"python3",
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
if (allowedProcesses.includes(command)) {
|
|
39
|
+
targets.push({ pid, port, command });
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
if (targets.length === 0) {
|
|
44
|
+
console.log("β
No dev servers found. All ports clean.\n");
|
|
45
|
+
process.exit(0);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
console.log("β οΈ Found running servers:\n");
|
|
49
|
+
|
|
50
|
+
targets.forEach((t) => {
|
|
51
|
+
console.log(`β’ ${t.command} running on port ${t.port} (PID ${t.pid})`);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
console.log("\nπ§Ή Cleaning ports...\n");
|
|
55
|
+
|
|
56
|
+
targets.forEach((t) => {
|
|
57
|
+
try {
|
|
58
|
+
process.kill(t.pid, "SIGKILL");
|
|
59
|
+
console.log(`β
Killed ${t.command} on port ${t.port}`);
|
|
60
|
+
} catch (err) {
|
|
61
|
+
console.log(`β οΈ Could not kill PID ${t.pid}`);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
console.log("\nπ All development ports cleaned!\n");
|
|
66
|
+
|
|
67
|
+
} catch (err) {
|
|
68
|
+
console.log("β
No listening processes found.");
|
|
69
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "portcleaner",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A CLI utility that detects and terminates stuck development servers to free ports.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"preferGlobal": true,
|
|
7
|
+
"bin": {
|
|
8
|
+
"cleanports": "./bin/cleanports.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"postinstall": "node scripts/postinstall.js"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=16"
|
|
15
|
+
},
|
|
16
|
+
"keywords": ["ports", "kill-port", "dev-tools", "node", "cli"],
|
|
17
|
+
"author": "Shubhashish Chakraborty",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"type": "commonjs"
|
|
20
|
+
}
|