36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
const { execSync } = require('child_process');
|
|
|
|
console.log('🛑 Stopping FileShare background servers on ports 3000 and 4000...');
|
|
|
|
const ports = [3000, 4000];
|
|
const isWindows = process.platform === 'win32';
|
|
|
|
ports.forEach((port) => {
|
|
try {
|
|
if (isWindows) {
|
|
const output = execSync(`netstat -ano | findstr LISTENING | findstr :${port}`, { encoding: 'utf8' }).trim();
|
|
const lines = output.split('\n');
|
|
lines.forEach((line) => {
|
|
const parts = line.trim().split(/\s+/);
|
|
const pid = parts[parts.length - 1];
|
|
if (pid && !isNaN(parseInt(pid))) {
|
|
console.log(`Killing process on port ${port} (PID: ${pid})...`);
|
|
try {
|
|
execSync(`taskkill /F /PID ${pid}`, { stdio: 'ignore' });
|
|
} catch {
|
|
// Already exited
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
execSync(`fuser -k ${port}/tcp || true`, { stdio: 'ignore' });
|
|
}
|
|
} catch {
|
|
// Port not open
|
|
}
|
|
});
|
|
|
|
console.log('✅ Ports 3000 and 4000 are now clear.');
|