Created
August 22, 2025 16:26
-
-
Save p32929/a525c433871f14857b12305b47f0961b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const { exec } = require('child_process'); | |
const port = process.argv[2] || '3000'; | |
console.log(`π Checking for processes on port ${port}...`); | |
// Kill processes on the specified port | |
exec(`lsof -ti:${port}`, (error, stdout, stderr) => { | |
if (error) { | |
console.log(`β No processes found on port ${port}`); | |
return; | |
} | |
const pids = stdout.trim().split('\n').filter(pid => pid); | |
if (pids.length === 0) { | |
console.log(`β No processes found on port ${port}`); | |
return; | |
} | |
console.log(`π― Found ${pids.length} process(es) on port ${port}`); | |
console.log(`PIDs: ${pids.join(', ')}`); | |
// Kill each process | |
pids.forEach(pid => { | |
exec(`kill -9 ${pid}`, (killError) => { | |
if (killError) { | |
console.log(`β Failed to kill process ${pid}:`, killError.message); | |
} else { | |
console.log(`β Killed process ${pid}`); | |
} | |
}); | |
}); | |
// Also try to kill any next dev processes | |
exec(`pkill -f "next dev"`, (pkillError) => { | |
if (!pkillError) { | |
console.log(`β Killed any remaining next dev processes`); | |
} | |
}); | |
setTimeout(() => { | |
console.log(`π Port ${port} should now be available`); | |
}, 1000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment