port-nuker 1.0.3 → 1.0.4

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.
Files changed (3) hide show
  1. package/README.md +23 -0
  2. package/index.js +59 -7
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -32,6 +32,9 @@ nuke <PORT>
32
32
  # Kill and wait until port is actually free
33
33
  nuke <PORT> --wait
34
34
 
35
+ # Force kill even on protected ports
36
+ nuke <PORT> --force
37
+
35
38
  # List all active ports and select one to kill interactively
36
39
  nuke list
37
40
  ```
@@ -87,6 +90,7 @@ nuke 5000 --wait && echo "Port is free!"
87
90
  ## Features
88
91
 
89
92
  - **Cross-Platform**: Works on Windows (using `netstat` + `taskkill`) and Unix-like systems (Linux/macOS using `lsof` + `kill`)
93
+ - **Safe Mode Protection**: Protected ports (22, 80, 443, 3306, 5432, 6379, 27017, 5000, 8080) require `--force` flag to prevent accidental termination of critical services
90
94
  - **Interactive Mode**: Browse all active ports with `nuke list` and select which one to kill
91
95
  - **Wait Mode**: Block until port is actually released with `--wait` flag for safe command chaining
92
96
  - **Detailed Process Info**: See PID, command name, user, memory usage, and protocol for each port
@@ -113,6 +117,25 @@ nuke 8080
113
117
  node server.js
114
118
  ```
115
119
 
120
+ ### Protected Ports (Safe Mode)
121
+
122
+ ```bash
123
+ # Attempting to kill a protected port (e.g., SSH on 22)
124
+ nuke 22
125
+ # Output:
126
+ # ⚠️ Port 22 is protected (SSH).
127
+ # This port is typically used for critical services.
128
+ # Use --force to override: nuke 22 --force
129
+
130
+ # Force kill a protected port
131
+ nuke 443 --force
132
+ # Successfully nukes the process on port 443 (HTTPS)
133
+
134
+ # Protected ports: 22 (SSH), 80 (HTTP), 443 (HTTPS), 3306 (MySQL),
135
+ # 5432 (PostgreSQL), 6379 (Redis), 27017 (MongoDB),
136
+ # 5000 (Flask/Docker), 8080 (Alt HTTP)
137
+ ```
138
+
116
139
  ## Requirements
117
140
 
118
141
  - Node.js >= 12.0.0
package/index.js CHANGED
@@ -5,16 +5,34 @@ const os = require('os');
5
5
  const inquirer = require('inquirer');
6
6
  const Table = require('cli-table3');
7
7
 
8
+ // Protected ports that require --force flag
9
+ const SAFE_PORTS = [22, 80, 443, 3306, 5432, 6379, 27017, 5000, 8080];
10
+
11
+ const SAFE_PORT_DESCRIPTIONS = {
12
+ 22: 'SSH',
13
+ 80: 'HTTP',
14
+ 443: 'HTTPS',
15
+ 3306: 'MySQL',
16
+ 5432: 'PostgreSQL',
17
+ 6379: 'Redis',
18
+ 27017: 'MongoDB',
19
+ 5000: 'Flask/Docker Registry',
20
+ 8080: 'Alternative HTTP'
21
+ };
22
+
8
23
  const args = process.argv.slice(2);
9
24
 
10
25
  // Parse arguments
11
26
  let port = null;
12
27
  let shouldWait = false;
28
+ let shouldForce = false;
13
29
  let command = null;
14
30
 
15
31
  for (let i = 0; i < args.length; i++) {
16
32
  if (args[i] === '--wait') {
17
33
  shouldWait = true;
34
+ } else if (args[i] === '--force') {
35
+ shouldForce = true;
18
36
  } else if (args[i] === 'list') {
19
37
  command = 'list';
20
38
  } else if (!isNaN(args[i])) {
@@ -26,16 +44,34 @@ for (let i = 0; i < args.length; i++) {
26
44
  if (command === 'list') {
27
45
  listPorts();
28
46
  } else if (port) {
29
- // nuke <PORT> [--wait]
30
- nukePort(port, shouldWait);
47
+ // nuke <PORT> [--wait] [--force]
48
+ nukePort(port, shouldWait, shouldForce);
31
49
  } else {
32
50
  console.error('Usage:');
33
- console.error(' nuke <PORT> Kill process on specific port');
34
- console.error(' nuke <PORT> --wait Kill process and wait until port is free');
35
- console.error(' nuke list List all active ports and select one to kill');
51
+ console.error(' nuke <PORT> Kill process on specific port');
52
+ console.error(' nuke <PORT> --wait Kill process and wait until port is free');
53
+ console.error(' nuke <PORT> --force Force kill even on protected ports');
54
+ console.error(' nuke list List all active ports and select one to kill');
55
+ console.error('');
56
+ console.error('Protected ports (require --force): 22, 80, 443, 3306, 5432, 6379, 27017, 5000, 8080');
36
57
  process.exit(1);
37
58
  }
38
59
 
60
+ // Check if a port is protected and requires --force flag
61
+ function checkSafePort(port, force) {
62
+ const portNum = parseInt(port);
63
+
64
+ if (SAFE_PORTS.includes(portNum) && !force) {
65
+ const description = SAFE_PORT_DESCRIPTIONS[portNum] || 'System Service';
66
+ console.error(`\n⚠️ Port ${port} is protected (${description}).`);
67
+ console.error(` This port is typically used for critical services.`);
68
+ console.error(` Use --force to override: nuke ${port} --force\n`);
69
+ return false;
70
+ }
71
+
72
+ return true;
73
+ }
74
+
39
75
  // List all active ports with process details
40
76
  function listPorts() {
41
77
  const platform = os.platform();
@@ -235,11 +271,22 @@ async function promptKillProcess(processes) {
235
271
  if (answer.pid) {
236
272
  const selectedProcess = processes.find(p => p.pid === answer.pid);
237
273
 
274
+ // Check if port is protected
275
+ const portNum = parseInt(selectedProcess.port);
276
+ const isProtected = SAFE_PORTS.includes(portNum);
277
+
278
+ let confirmMessage = `Kill process ${selectedProcess.command} (PID: ${answer.pid}) on port ${selectedProcess.port}?`;
279
+
280
+ if (isProtected) {
281
+ const description = SAFE_PORT_DESCRIPTIONS[portNum] || 'System Service';
282
+ confirmMessage = `⚠️ Port ${selectedProcess.port} is protected (${description}).\n Kill process ${selectedProcess.command} (PID: ${answer.pid})?`;
283
+ }
284
+
238
285
  const confirm = await inquirer.prompt([
239
286
  {
240
287
  type: 'confirm',
241
288
  name: 'confirmed',
242
- message: `Kill process ${selectedProcess.command} (PID: ${answer.pid}) on port ${selectedProcess.port}?`,
289
+ message: confirmMessage,
243
290
  default: false
244
291
  }
245
292
  ]);
@@ -335,7 +382,12 @@ function pollPortUntilFree(port, maxWaitSeconds = 30) {
335
382
  }
336
383
 
337
384
  // Original nuke port function
338
- function nukePort(port, shouldWait = false) {
385
+ function nukePort(port, shouldWait = false, shouldForce = false) {
386
+ // Check if port is protected
387
+ if (!checkSafePort(port, shouldForce)) {
388
+ process.exit(1);
389
+ }
390
+
339
391
  const platform = os.platform();
340
392
  let findCommand;
341
393
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "port-nuker",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "A simple CLI utility to kill processes holding a specific port. Solves EADDRINUSE errors instantly.",
5
5
  "main": "index.js",
6
6
  "bin": {